Nhibernate3.0cookbook学习笔记一个基类实体类-创新互联
![](/upload/ad_content/xuanchuantu-30.jpg)
using System;
namespace Eg.Core
{
public abstract class Entity
{
public virtual TId Id { get; protected set; }
protected virtual int Version { get; set; }
public override bool Equals(object obj)
{
return Equals(obj as Entity);
}
private static bool IsTransient(Entity obj)
{
return obj != null &&
Equals(obj.Id,default(TId));
}
private Type GetUnproxiedType()
{
return GetType();
}
public virtual bool Equals(Entity other)
{
if (other == null)
return false;
if (ReferenceEquals(this, other))
return true;
if (!IsTransient(this) &&
!IsTransient(other) &&
Equals(Id, other.Id))
{
var otherType = other.GetUnproxiedType();
var thisType = GetUnproxiedType();
return thisType.IsAssignableFrom(otherType) ||
otherType.IsAssignableFrom(thisType);
}
return false;
}
public override int GetHashCode()
{
if (Equals(Id, default(TId)))
return base.GetHashCode();
return Id.GetHashCode();
}
}
public abstract class Entity : Entity
{
}
}
![](/upload/otherpic7/copycode.gif)
当前题目:Nhibernate3.0cookbook学习笔记一个基类实体类-创新互联
文章来源:http://jxruijie.cn/article/ijhco.html