I have a domain class that looks like this. I want NHibernate to save the current value of LastUpdate
when inserting/updating so that I can use it in queries, but to ignore it when retrieving a Foo
from the database and let the object itself recalculate the value when I actually access it.
public class Foo {
public DateTime LastUpdate {
get {
/* Complex logic to determine last update by inspecting History */
return value;
}
}
public IEnumerable<History> History { get; set; }
/* etc. */
}
My mapping for Foo
looks like this:
public class FooMap : ClassMap<Foo> {
Map(x => x.LastUpdate)
.ReadOnly();
HasMany(x => x.History);
// etc...
}
I thought that ReadOnly()
was what I wanted to accomplish this, but when I try to create a SessionFactory I get the following exception:
Error: FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.PropertyNotFoundException: Could not find a setter for property 'LastUpdate' in class 'Foo'.
The property doesn't have a setter because it shouldn't be set, only read from. Is ReadOnly()
the correct thing to do here? If not, what?
(NHibernate v3.0b1, Fluent NHibernate v1.1)