Setting SelfServicing PrimaryKey fields

Posts   
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 14-Jan-2009 18:24:19   

The adapter code lets the primary key fields be set but the self servicing does not, throws the read only error:

OrderEntity order = new OrderEntity(); order.IsNew = false; order.OrderId = 27; --THROWS ERROR WITH SelfServicing

Looking at the source code, the ValidateValue method of EntityBase2 allows PrimaryKey + ReadOnly combinations while EntityBase.ValidateValue just looks at ReadOnly.

Is it possible to get the SelfServicing to behave the same as the Adapter?

Brian Chance

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Jan-2009 03:09:56   

This is the lazy-loading of SelfServicing template. As the field is PK and Identity, thus Read-Only, it can't be updated. Why do you want set a value on that field?

David Elizondo | LLBLGen Support Team
Posts: 134
Joined: 10-Jan-2007
# Posted on: 15-Jan-2009 03:29:09   

If I already know the id, I can just set the values (like from a web form post).

like: Order order = new Order(); order.IsNew = false; order.OrderId = 27; order.Total = 125.00; order.Save();

I know I could load it from the database, but want to save the trip (and simplify some code).

_And _it works with the adapter.

Brian

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Jan-2009 04:18:34   

I see. In that case please use ForcedCurrentValueWrite:

order.Fields["OrderId"].ForcedCurrentValueWrite(27);
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Jan-2009 10:01:59   

The reason it works in adapter, is that in adapter you need to set the PK to fetch an entity using FetchEntity(). In selfservicing, you don't use that pattern.

Setting the PK which is an identity is hardly necessary, only when you use it as an entity for direct updates or when you want to change the PK (which is not recommended).

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 15-Jan-2009 14:57:01   

I really only wanted to set the PK then force an update using IsNew=false.

Will use the ForcedCurrentValueWrite().

Thanks.