[英]Can NHibernate set non-public properties?
Is it possible to setup NHibernate to load/persist a non-public property of a class? 是否可以设置NHibernate来加载/持久化类的非公共属性? For example I may have an Item class as follows. 例如,我可能有一个Item类,如下所示。
public class Item
{
public int ItemID {get; set;}
public string Name{get; set;}
}
With the following mapping: 使用以下映射:
<class name="RCL.Item" table="Items">
<id name="ItemID" type="Int32" column="ItemID">
<generator class="native"/>
</id>
<property name="Author" />
</class>
However I really don't want the consumers of my Item class to be able to change the ItemID field. 但是我真的不希望我的Item类的使用者能够更改ItemID字段。 Can I restrict access to the set accessor of ItemID? 我可以限制对ItemID的set访问器的访问吗? If so what should I set it to? 如果是这样我应该将它设置为什么? Private, protected, internal, protected internal? 私人,受保护,内部,受保护的内部?
From the NHibernate tutorial: 从NHibernate教程:
Properties need not be declared public - NHibernate can persist a property with an internal, protected, protected internal or private visibility. 不需要将属性声明为公共 - NHibernate可以持久保存具有内部,受保护,受保护的内部或私有可见性的属性。
Just set the ItemID to private 只需将ItemID设置为私有
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.