Hello,
We're having some problems with the proxies NHibernate generates.
All our mapped entities inherit from a generic class DomainEntity<T>:
Code:
public abstract class DomainEntity<T>
{
private T _id = default(T);
public virtual T Id
{
get { return _id; }
set { _id = value; }
}
public abstract String Label { get; }
/// <summary>
/// Equals
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public override bool Equals(object other)
{
if (this == other)
return true;
if (!GetType().Equals(other.GetType()))
return false;
DomainEntity<T> otherAsDomain = other as DomainEntity<T>;
if (otherAsDomain == null)
return false;
if (otherAsDomain.Id == null)
return false;
if (Id == null)
return false;
if ((Id.Equals(default(T))) || (otherAsDomain.Id.Equals(default(T))))
return false;
return _id.Equals(otherAsDomain.Id);
}
/// <summary>
/// GetHashCode
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
unchecked
{
int result;
result = Id.GetHashCode();
result = 29 * result;
return result;
}
}
}
We're getting some errors like this:
[ArgumentException: No se puede resolver el método Int32 GetHashCode() porque el tipo declarativo del identificador de método M2.Domain.DomainEntity`1[T] es genérico. Proporcione explícitamente el tipo declarativo a GetMethodFromHandle. ]
System.Reflection.MethodBase.GetMethodFromHandle(RuntimeMethodHandle handle) +2336241
CProxyTypePostalAddressEntityDomain_INHibernateProxy_ISerializable2.GetHashCode() +61
System.ComponentModel.WeakKeyComparer.System.Collections.IEqualityComparer.GetHashCode(Object obj) +28
System.Collections.Hashtable.GetHash(Object key) +16
System.Collections.Hashtable.get_Item(Object key) +67
System.ComponentModel.TypeDescriptor.NodeFor(Object instance, Boolean createDelegator) +46
System.ComponentModel.TypeDescriptor.NodeFor(Object instance) +27
System.ComponentModel.TypeDescriptor.GetDescriptor(Object component, Boolean noCustomTypeDesc) +247
System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes) +132
System.ComponentModel.TypeDescriptor.GetProperties(Object component, Boolean noCustomTypeDesc) +36
System.ComponentModel.TypeDescriptor.GetProperties(Object component) +27
System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +150
System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +32
System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +460
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +79
System.Web.UI.WebControls.ListControl.PerformSelect() +32
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
Customer_Edit.InitializeModel() in c:\Proyectos\M2\bss\trunk\dotnet\src\M2.Web.Backoffice\Customer\Edit.aspx.cs:227
Spring.Web.UI.Page.OnInit(EventArgs e) +81
System.Web.UI.Control.InitRecursive(Control namingContainer) +459
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1742
(The message says in spanish that the "Int32 GetHashCode()" cannot be resolved because the declaring type is generic, and that it should be resolved by passing the declarative type to GetMethodFromHandle).