Entity by Unique Keys

Posts   
 
    
sams
User
Posts: 3
Joined: 13-May-2008
# Posted on: 13-May-2008 18:00:40   

Hi all,

Is it possible (in adapter mode) to fetch an entity like this

UserAliasEntity userAliasEntity = new UserAliasEntity(domainName,userName); adapter.FetchEntity(userAliasEntity);

DomainName and UserName are a unique key on the database, the only way I know to do that is using the entity collection, and take the fist record that is found. But, because it will always find one or none records, I think this is not the best way to do this (it does not seems logical)

Is there any way to generate entity classes where you can pass the unique keys in the constructor? This would make my coding mutch easier.

Kind Regards,

Sam

Posts: 1263
Joined: 10-Mar-2006
# Posted on: 13-May-2008 20:08:23   

You sure can:

UserAliasEntity UserAliasEntity userAliasEntity = new UserAliasEntity();

//note this FetchUCxxxxxx will vary depending on the constraint used.... userAliasEntity.FetchUCDomainUserName(domain,username);

these methods are generated for every unique constraint you have defined.

sams
User
Posts: 3
Joined: 13-May-2008
# Posted on: 14-May-2008 09:23:49   

It is only possible to use the fetch methods on the adapter. Or is there a way to let llblgen generete them in adapter mode?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 14-May-2008 09:35:17   

This is also supported in the Adapter model.

eg (from the manual):

// [C#]
DataAccessAdapter adapter = new DataAccessAdapter();
CustomerEntity customer = new CustomerEntity();
customer.CompanyName = "Chop-suey Chinese";
adapter.FetchEntityUsingUniqueConstraint(customer, customer.ConstructFilterForUCCompanyName());

Note: This works with database Unique Keys not Unique Indexes.

sams
User
Posts: 3
Joined: 13-May-2008
# Posted on: 14-May-2008 10:06:30   

OK, I found it, I needed an Unique Key on the database instead of an Index that is unique. Is it possible to generate the ConstructFilterFor... also when using an unique index?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 14-May-2008 10:10:14   

I'm afraid it's not possible.