Nhibernate3.0cookbook学习笔记一个基类实体类-创新互联

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

标题名称:Nhibernate3.0cookbook学习笔记一个基类实体类-创新互联
URL分享:http://pwwzsj.com/article/ijhco.html