Well, it seems that this does not work, since a readonly field is never emited back to the database through the generated sql.
I took some ideas from this thread:
http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=14821
but I did not implement the solution proposed there.
I consider this functionality as part of the DAL thus I don't want to involve the BL in this. We are also using LLBLGenDataSource2 heavily thus I need this to be transparent there too!
What I did was something along the following lines:
public partial class TypeASecurityEntity
{
private bool _allowSecurityTypeUpdate = false;
protected override void OnInitialized()
{
base.OnInitialized();
_allowSecurityTypeUpdate = true;
this.SecurityType = "A";
_allowSecurityTypeUpdate = false;
}
protected override bool OnValidateFieldValue(int fieldIndex, object value)
{
if (fieldIndex == (int)TypeASecurityFieldIndex.SecurityType)
{
if (_allowSecurityTypeUpdate && value.ToString().Equals("A"))
{
return true;
}
return false;
//throw new ORMFieldIsReadonlyException("You are not allowed to modify the 'SecurityType' field.");
}
return base.OnValidateFieldValue(fieldIndex, value);
}
}
where TypeASecurity is a Sub-Entity of SecurityEntity and the discriminator property is 'SecurityType'.
This seems to work since the value is set correctly when I create a new TypeASecurityEntity and when I set the value through code
TypeASecurityEntity typeA = new TypeASecurityEntity();
typeA..SecurityType = "C";
the new value is ignored by the framework.
I also considered throwing an Exception in case the value is set. The fact that the 'client' code behaves differently than expected is the only bad smell I get from this approach. But so far it serves the purpose.
Thanks again for directing me.
Chris