开发者

Can NHibernate set non-public properties?

Is it possible to setup NHibernate to load/persist a non-public property of a class? For example I may have an Item class as follows.

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. Can I restrict access to the set accessor of ItemID? If so what should I set it to? Private,开发者_高级运维 protected, internal, protected internal?


From the NHibernate tutorial:

Properties need not be declared public - NHibernate can persist a property with an internal, protected, protected internal or private visibility.

Just set the ItemID to private

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜