b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

nhibernate_nhibernate nuget_nhibernate 一对多(6)

电脑杂谈  发布时间:2017-04-03 07:05:23  来源:网络整理

8. 添加另一个类文件:Name.cs,添加如下代码定义Name值对象:

public class Name
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MiddleName { get; set; }

    public bool Equals(Name other)
    {
        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;
        return Equals(other.FirstName, FirstName) &&
        Equals(other.LastName, LastName) &&
        Equals(other.MiddleName, MiddleName);
    }
    public override bool Equals(object obj)
    {
        if (obj.GetType() != typeof(Name)) return false;
        return Equals((Name)obj);
    }
    public override int GetHashCode()
    {
        unchecked
        {
            int result = (FirstName != null ?
            FirstName.GetHashCode() : 0);
            result = (result * 397) ^ (LastName != null ?
            LastName.GetHashCode() : 0);
            result = (result * 397) ^ (MiddleName != null ?
            MiddleName.GetHashCode() : 0);
            return result;
        }
    }
}

9. 在项目中添加一个XML文件:Person.hbm.xml,并将它的Build Action属性设置为Embedded Resource。

10. 在Person.hbm.xml中添加如下代码定义Person实体的映射:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="LoquaciousConfigurationSample" namespace="LoquaciousConfigurationSample" >
  <class name="Person" lazy="false">
    <id name="Id">
      <generator class="guid.comb"/>
    </id>
    <component name="Name">
      <property name="FirstName"/>
      <property name="LastName"/>
      <property name="MiddleName"/>
    </component>
    <property name="SSN"/>
    <property name="Birthdate"/>
  </class>
</hibernate-mapping>


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-39178-6.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...