ForcedValueCurrentWrite

Posts   
 
    
BOb
User
Posts: 12
Joined: 29-Jun-2005
# Posted on: 26-Oct-2005 12:34:47   

I am trying to update a row in the table by using the Option 2 method as per your help docs in the Using Entity Classes chapter

Because my PK is an identity column in MS-SQL it is read only so therefore causes an exception.

Searching the forum I found the above named method that gets around this problem.

My issues are :

a) Please could you make the help docs better by explaining that the option 2 method only works if the PK is not read only

b) The reference manual says that I should not use the ForcedValue.... method, so what should I be using if I want to follow the Option 2 way of updating data in a stateless envionment where I do not hold a copy of the data being editied in memory ?

Thanks

BOb

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Oct-2005 16:07:55   

Are you trying to update the Identity PK column?

ForcedCurrentValueWrite, updated a readonly field already fetched from the database!! Not the other way around.

The mentioned Option 2: uses a PK value to identify the row that should be updated with other fields values.

BOb
User
Posts: 12
Joined: 29-Jun-2005
# Posted on: 26-Oct-2005 17:03:31   

No I am not trying to update the primary key, just tell the entity which row (PK) I want to update

The setting of the value into ht eId column causes the reead-only exception, not a write to the database.

you said The mentioned Option 2: uses a PK value to identify the row that should be updated with other fields values.

This is not correct, it identifies the row that needs to be updated, that is what I am trying to do as my code below shows

        // need to tell the ORM the id of the row being updated

        addressEntity.Fields["ADD_Id"].ForcedCurrentValueWrite(address.Id);

       // addressEntity.ADD_Id = address.Id -  causes error

        // force an update rather than a create - to create dont set the property
        addressEntity.IsNew = false;

        addressEntity.ADD_Code = address.Code;
        addressEntity.ADD_Address1 = address.Address1;

        // do it
        addressEntity.Save();

Thanks

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Oct-2005 17:08:13   

ForcedCurrentValueWrite is discouraged because it surpasses changetracking of the field. In Selfservicing this is the only way to use an entity to update an entity directly if the PK is an identity (which is readonly).

Frans Bouma | Lead developer LLBLGen Pro