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
那一千五都没有
期待