EntityCollection -Readonly error...

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 27-Mar-2006 23:57:35   

Hi all,

I'm not sure what I'm doing wrong, but I'm getting this error:

The field is marked readonly and cannot 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 is marked readonly and cannot be changed.

Source Error:

Line 402: _campaign = CType(relatedEntity, CampaignEntity) Line 403: AddHandler _campaign.AfterSave, AddressOf OnEntityAfterSave Line 404: MyBase.SetEntitySyncInformation("Campaign", _campaign, CampParmEntity.Relations.CampaignEntityUsingCampaignID) Line 405: Line 406: End If

Source File: C:\Multi-Vision\Projects\SpeechezyWeb3\Data Access Layer\DatabaseGeneric\EntityClasses\CampParmEntity.vb Line: 404

Here is my code:

    Dim _CP As DataAccessLayer.EntityClasses.SEZCampParmEntity = New DataAccessLayer.EntityClasses.SEZCampParmEntity
    _CP.Name = "MyParameterName"
    _CP.Value = "123456"
    _Campaign.CampParmCollection.Add(_CP) <== Failed

Any ideas why I can't add an entity to my collection? Where can I check for readonly flags on a collection?

I'm using the SubClass templates. Thanks.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 28-Mar-2006 00:23:01   

I have found that sometimes error messages are misleading and not to be taken literally.

Is there any chance that _campaign Is Nothing when you try to add _CP to the collection?

mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 28-Mar-2006 00:31:47   

Just found the issue...

My object - CampParmEntity had a read-onyl flag set on the CampaignID field.

However, CampaignID is a FK field... So LLBLGen internally updates CampaignID - but since it was set to Readonly, it threw an exception rage

Now that I've removed the readonly flag on the FK field, all is good - but now people can also switch the FKs of the object.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 28-Mar-2006 00:43:07   

If you want to leave the field read only most of the time, you can use ForcedCurrentValueWrite for the exception to the rule.

From 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).

mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 29-Mar-2006 07:28:52   

JimHugh wrote:

If you want to leave the field read only most of the time, you can use ForcedCurrentValueWrite for the exception to the rule.

From 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).

AH perfect! Thank you simple_smile