Fluent NHibernate: How to map an entire class as ReadOnly?
I have a few classes that read from very delicate tables, which is why I want them to be used by NHibernate as "ReadOnly". Establishing .ReadOnly() on each field map is really sloppy, and I'm not sure I trust it. How do I setup a class to 开发者_StackOverflowbe entirely readonly, as I can easily do with traditional XML mappings?
Edit: The answer does work. I expected it to throw an exception if I tried to save over a ReadOnly() object, but it just silently does so.
Thanks.
With Fluent NHibernate, it's as simple as:
class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
ReadOnly();
// Mappings
}
}
The ReadOnly() property actually does NOT work like you would expect. Using this property makes sure that the objects that you retrieve are read-only, so you cannot UPDATE them. However, it does NOT prevent the creation of new records or even the deletion of existing records in the database!
精彩评论