Calculated property in model and Content Manager.

Topics: Core, Writing modules
Aug 5, 2013 at 9:36 PM
I have a calculated field in my model
ex:
public virtual decimal Total
{
    get { return SubTotal + Vat; }            
}
Getting the error "NHibernate.PropertyNotFoundException: Could not find a setter for property 'Total'" when updating the database.

I tried to put an empty setter:
public virtual decimal Total
{
    get { return SubTotal + Vat; }
    set { }            
}
Now I get the following error:
NHibernate.Exceptions.GenericADOException: could not insert: ... Invalid column name 'Total'.

Is there a way to have a calculated property in a model and inform the persistence layer that it is readonly?

Thanks in advance.
Coordinator
Aug 5, 2013 at 11:53 PM
Don't put it on the record, put it on the part instead.
Aug 12, 2013 at 2:24 PM
I had one class playing the role of part and record. I was too lazy to split them up (shame on me).
I noticed that putting the set method as protected internal worked but you are right, It's cleaner to split in two classes. So that's what I did.

Thanks again.
Aug 12, 2013 at 3:44 PM
For regular records you could have used a virtual method instead of a property ;)

But yeah, the Part is the place for ContentPart records.