Loading Entity By PrimeryKey

Posts   
 
    
Behdad
User
Posts: 12
Joined: 08-Jun-2010
# Posted on: 03-Jul-2010 17:53:19   

Hi I have a customer entity and want to load it with pk process it and load with another primerykey.I think it should be like this:

DataAccessAdapter adapter = new DataAccessAdapter(); CustomerEntity customer = new CustomerEntity("CHOPS"); adapter.FetchEntity(customer); customer = new CustomerEntity("pk2"); adapter.FetchEntity(customer); customer = new CustomerEntity("pk3"); adapter.FetchEntity(customer);

But is there a better way by just loading by primerykey and without instancing a new instance? like following seudo code?

DataAccessAdapter adapter = new DataAccessAdapter(); CustomerEntity customer = new CustomerEntity("CHOPS"); adapter.FetchEntity(customer); customer.loadbyPk("pk2"); customer.loadbyPk("pk3");

Regards

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 04-Jul-2010 11:51:07   

Please check out the reference manual of the runtime library and in that the DataAccessAdapterBase class. (or for example the manual in which we describe how to fetch an entity)

For example, you can also use FetchNewEntity: var c = new DataAccessAdapter().FetchNewEntity<CustomerEntity>( new RelationPredicateBucket(CustomerFields.CustomerId=="CHOPS"));

Frans Bouma | Lead developer LLBLGen Pro
Behdad
User
Posts: 12
Joined: 08-Jun-2010
# Posted on: 04-Jul-2010 12:38:10   

Hi I am using LLbLGen ProRuntime Framework version: 3.0.I didn't find a code sample that show how to fetch an entity without creating a new entity.Your provided code sample creates another new entity. I want to create an entity and load it with different primery key , use the entity and fetch by another primerykey.I don't want new entity ,just loading data to previously created entity.

Regards

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Jul-2010 21:46:45   
DataAccessAdapter adapter = new DataAccessAdapter();
CustomerEntity customer = new CustomerEntity("CHOPS");
adapter.FetchEntity(customer);
customer.loadbyPk("pk2");
customer.loadbyPk("pk3");

That code is ok, but it contradict the fact that in Adapter mode, the model and the data-access should be separated. If you want something like that you can try SelfServicing. In SelfServicing you can do something similar:

// load ALFKI
customer = new CustomerEntity("ALFKI");
// load RGPD
customer = new CustomerEntity("RGPD");

//OR
customer.CustomerId ="ALFKI";
customer.Refetch;
customer.CustomerId = "RGPD";
customer.Refetch;

To understand the differences between Adapter and SelfServicing please read this.

David Elizondo | LLBLGen Support Team