Modifying an entity option 2 read-only error

Posts   
 
    
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 27-Apr-2009 01:26:54   

I'm trying to update an entity using the method detailed under option 2 in "Modifying an entity" in the 2.6 documentation.

Dim o As New StoreItemTypesEntity()
o.StoreItemTypeId = storeItemTypeId
o.IsNew = False
o.StoreItemType = "x"
o.TypeDescription = "x"
o.Save()

StoreItemTypeId is table's primary key.

Using the code above I'm getting the following error:

The field 'StoreItemTypeId' is read-only and can't be changed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: SD.LLBLGen.Pro.ORMSupportClasses.ORMFieldIsReadonlyException: The field 'StoreItemTypeId' is read-only and can't be changed.

Source Error:

Line 774: End Get Line 775: Set Line 776: SetValue(CInt(StoreItemTypesFieldIndex.StoreItemTypeId), value, True) Line 777: End Set Line 778:

Source File: C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\NSA\InStoreChamp.DLL\EntityClasses\StoreItemTypesEntity.vb Line: 776

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Apr-2009 03:55:47   

This is caused by the identity primary key used in SelfServicing scenario. Please check this note on the manual:

If you want to set an identity primary key column, you'll notice you can't do that because it is marked as read-only. Use the method entityObject.Fields[fieldindex or fieldname].ForcedCurrentValueWrite(value). See the reference manual for details about this method (EntityField.ForcedCurrentValueWrite).

David Elizondo | LLBLGen Support Team
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 27-Apr-2009 10:00:16   

daelmo wrote:

This is caused by the identity primary key used in SelfServicing scenario. Please check this note on the manual:

If you want to set an identity primary key column, you'll notice you can't do that because it is marked as read-only. Use the method entityObject.Fields[fieldindex or fieldname].ForcedCurrentValueWrite(value). See the reference manual for details about this method (EntityField.ForcedCurrentValueWrite).

Thanks. I should have the following part:

If you want to set an identity primary key column, you'll notice you can't do that because it is marked as read-only. Use the method entityObject.Fields[fieldindex or fieldname].ForcedCurrentValueWrite(value). See the reference manual for details about this method (EntityField.ForcedCurrentValueWrite).