如何做才能让你的NHibernate忽略的属性在POCO让你、如何做、属性、才能

2023-09-04 23:46:02 作者:嘴硬欠吻

我们有POCO,是这样的:

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; }
}

和相应的HBM文件

<?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>

如果你仔细观察,我们有一个版本属性,其中有在数据库中没有列?我们只是想NHibernate的忽略这个属性,这就是我们没有把属性映射文件的原因。但是相反,它开始抛出错误。

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.

有没有解决的办法吗?

推荐答案

您应该使所有成员的虚拟,而不是图你想忽略的属性。

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