Create entity from non-key field

Posts   
 
    
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 16-Mar-2006 23:26:47   

Hey Frans -

How do I create an entity on a non-key field? I.e.

NewEntity entity = new NewEntity(non_key_field_value);

Do I have to go through an intermediate step like this:

int keyFieldValue = 0;
int nonKeyFieldValue = 100;
int KeyFieldValue = RetrieveProcedures.GetKeyValueFromTable(nonKeyFieldValue, ref keyFieldValue)
NewEntity entity = new NewEntity(KeyFieldValue);

Thanks!

Jeff

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 17-Mar-2006 03:13:02   

Is it a unique constriant?

You can use this from the docs if it is.

// [C#] CustomerEntity customer = new CustomerEntity(); customer.FetchUsingUCCompanyName("Chop-suey Chinese");

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 17-Mar-2006 04:04:33   

You could simply add a static method to the entity that uses an EntityCollection to do a search, which would return one result, and you could return that entity.

Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 17-Mar-2006 13:32:33   

Good ideas! Thanks.