连贯NHibernate:如何映射整个类为只读? [英] Fluent NHibernate: How to map an entire class as ReadOnly?
问题描述
我有一个从非常精致的表看了几类,这就是为什么我希望他们能够通过NHibernate的用作只读。每个字段地图上建立.ReadOnly()是真的马虎,我不知道我信任它。 ?如何设置一类是完全只读,因为我可以很容易地与传统的XML映射做
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 be 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.
感谢。
推荐答案
使用流利NHibernate的,这是一样简单
With Fluent NHibernate, it's as simple as:
class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
ReadOnly();
// Mappings
}
}
这篇关于连贯NHibernate:如何映射整个类为只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!