开发者

Can NHibernate set non-public properties?

开发者 https://www.devze.com 2023-01-21 14:48 出处:网络
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.

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

精彩评论

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

关注公众号