This project is read-only.

NHibernate error on 1.x

Topics: Customizing Orchard, Troubleshooting, Writing modules
Aug 20, 2012 at 11:24 PM
Edited Aug 21, 2012 at 7:02 AM

Hello everyone.

I'm facing a problem with the latest source and a module. I have this model:


    public class OrderDetailRecord {
        public virtual int Id { get; set; }
        public virtual int OrderRecord_Id { get; set; }
        public virtual int ProductId { get; set; }
        public virtual int Quantity { get; set; }
        public virtual decimal UnitPrice { get; set; }
        public virtual decimal VatRate { get; set; }    
        public virtual decimal UnitVat
            get { return UnitPrice * VatRate; }
        public virtual decimal Vat
            get { return UnitVat * Quantity; }
        public virtual decimal SubTotal
            get { return UnitPrice * Quantity; }
        public virtual decimal Total
            get { return SubTotal + Vat; }


and trying to activate the module I get the following error: 

NHibernate.PropertyNotFoundException: Could not find a setter for property 'UnitVat' in class 'Pss.Webshop.Models.OrderDetailRecord'

(UPDATE) I'm using Visual Studio 2012 on Windows 8.


Aug 21, 2012 at 8:35 AM

That's an easy one. The record should be a dumb data structure, a POCO without any smarts. Move those computed properties to the part.

Aug 21, 2012 at 9:23 AM

There is no content part. Using this as non content data.

Aug 21, 2012 at 10:22 AM

Unless NH has some attributes to ignore the computed properties, you could turn them into extension methods of the OrderDetailRecord class.

Aug 22, 2012 at 6:02 AM

Couldn't find any NH attributes to do the trick. Is it good idea to include those properties in a viewmodel and compute the values there?

Aug 22, 2012 at 6:38 AM

All the same. Don't use the record as more than a dumb representation of the data in the db.