Data Portal Create

Data Portal Create

Old forum URL: forums.lhotka.net/forums/t/1446.aspx


Wal972 posted on Wednesday, October 11, 2006

Hi

DataPortal Create, I can't get a valid code setting when I want to create a New Object with Defaults loaded from a database. Could someone please give a sample code with Create with Criteria model

Thanks

ajj3085 replied on Wednesday, October 11, 2006

// Don't make with RunLocal
private void DataPortal_Create( MyCriteria crit ) {
    MyBoDefaultLoader loader;

    loader = new MyBoDefaultLoader( crit );

    MyProperty1 = loader.MyProperty1Default;
}

public static MyBo NewMyBo( string defaultName ) {
    return DataPortal.Create<MyBo>( new MyCriteria( defaultName ) );
}

Obviously, MyBoDefaultLoader handles loading the defaults based on the given criteria.. you may use plain old System.Data objects though if you wish.. i just did it this way to give the basic concept.

HTH
Andy

Jav replied on Wednesday, October 11, 2006

What exactly do you mean by "I can't get a valid code setting"?  Are you saying that your object returns IsValid = False.  May be you should post your DataPortal_Create code so we can take a look at it.

jav

Wal972 replied on Wednesday, October 11, 2006

Hi Again,

I mean there is a sample from ProjectTracker on how to create a new BO with defaults that are loaded within the system.

However I there is not one for create with new defaults loaded from a database. and I can't get the right syntax. Do I use

Public Shared Function NewPay(Byval EmployeeID as int16) as pay

   return Dataportal.Create(of Pay) (New Criteria(EmployeeID)

End Function

And my Data Access Region code is ?

Private Overloads Sub DataPortal_Create(ByVal Criteria As Critieria)

End Sub

because it doesn't like it

Help Thanks

Ellie

RockfordLhotka replied on Wednesday, October 11, 2006

It should like that - at least in 2.1. Are you getting an exception at runtime? And if so, what exception? Ambiguous method? Or invalid operation?

Wal972 replied on Wednesday, October 11, 2006

I realised in my code I typed overrides not overloads. Whats the difference anyway ?

Brian Criswell replied on Thursday, October 12, 2006

Overrides means that the method signature matches the method signature of a method in the base class.  Overloads means that the method signature is does is different from at least one method signature of the same name in the base class.

RRorije replied on Friday, October 13, 2006

Well in short that is indeed the case. 'Overrides' replaces the function, as the word suggests, according to inheritance. 'Overloads' specifies that you create a new function which, coincedentially ;) has the same name. In most OO programming languages overloads is not used. It is implicitly available by specifying several functions with the same name.

Of topic, personally I do not see the need for the overloads keyword. Especially because it is not mandatory and you may not know in your base class whether you will overload the function later.


Copyright (c) Marimer LLC