How do you make NHibernate ignore a property in a POCO

浪子不回头ぞ 提交于 2019-12-23 07:06:08

问题


We have POCO, something like:

public class Person
{
    public Guid PersonID { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public DateTime DateOfBirth { get; set; }

    public string   Version {get; set; }
}

And the corresponding hbm file as

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.FirstAttempt"  namespace="NHibernate.FirstAttempt.Entity" >
  <class name="Person" lazy="false">
    <id name="PersonID">
      <generator class="guid" />
    </id>
    <property name="FirstName"  />
    <property name="LastName"     />
    <property name="DateOfBirth"  />
  </class>
</hibernate-mapping>

If you look closely, we have a Version property, for which there is no column in the database ? We just want nHibernate to ignore this property and that's the reason we did not put the property in the mapping file. But instead it started throwing error.

Is there a way around this ?


回答1:


You should make all members virtual and not map the property you want to ignore.



来源:https://stackoverflow.com/questions/5830649/how-do-you-make-nhibernate-ignore-a-property-in-a-poco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!