是否可以设置 NHibernate 来加载/保留类的非公共(public)属性?例如,我可能有一个 Item 类,如下所示。
public class Item
{
public int ItemID {get; set;}
public string Name{get; set;}
}
具有以下映射:
<class name="RCL.Item" table="Items">
<id name="ItemID" type="Int32" column="ItemID">
<generator class="native"/>
</id>
<property name="Author" />
</class>
但是我真的不希望我的 Item 类的使用者能够更改 ItemID 字段。我可以限制对 ItemID 的 set 访问器的访问吗?如果是这样,我应该将其设置为什么?私有(private)的、 protected 、内部的、 protected 内部?
最佳答案
来自 NHibernate 教程:
Properties need not be declared public - NHibernate can persist a property with an internal, protected, protected internal or private visibility.
只需将 ItemID 设置为私有(private)即可
关于c# - NHibernate 可以设置非公共(public)属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3973735/