Can't seem to fetch by field that is set to Identity but not PK

Posts   
 
    
rsiera
User
Posts: 48
Joined: 09-Oct-2011
# Posted on: 22-Jun-2015 00:11:30   

I have a SQL table with a int field defined as identity and a guid field as PK. On the int field I created a UniqueConstraint to be able to use FetchEntityUsingUniqueConstraint() But I can't seem do that. The documentation suggests this code:

item = new CustomerEntity();
item.CustomerIntId = 22;
adapter.FetchEntityUsingUniqueConstraint(item,item.ConstructFilterForUCTypeIntId());

but item.CustomerIntId has no setter because as identity field it is a read-only field.

Any suggestion of a different approach?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jun-2015 05:54:30   

This is a workaround:

entity.Fields[CustomerFieldIndex.CustomerIntId].ForcedCurrentValueWrite(22);
entity.Fields[CustomerFieldIndex.CustomerIntId].IsChanged = true;
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 22-Jun-2015 09:06:13   

or

var q = new QueryFactory().Customer.Where(CustomerFields.CustomerIntId==22);
var e = new DataAccessAdapter().FetchFirst(q);

or the linq variant.

Frans Bouma | Lead developer LLBLGen Pro
rsiera
User
Posts: 48
Joined: 09-Oct-2011
# Posted on: 22-Jun-2015 21:03:16   

Thx Guys!