I've read many posts here about exception mentioned in the title. Typically this exception means that somewhere I mapped to fields to one entity. I spent pretty much time looking at my mappings, but still can't find what's wrong. Could you please help me with understanding what've been done wrong here:
public class CustomerSegment : ModelEntity, IEntityDescriptor
{
public const string Standart = "Standard";
public virtual string Name { get; set; }
public virtual NetworkNHMapped Network { get; set; }
public virtual string GetDescriptor()
{
return Name;
}
}
public class CustomerSegmentMap : ClassMap<CustomerSegment>
{
public CustomerSegmentMap()
{
Table("NetworkProperty");
Id(x => x.Id).Column("NetworkPropertyId");
Map(x => x.Name).Column("PropertyName");
References(x => x.Network).Column("NetworkId");
}
}
}
The exception occurs when I'm trying get all CustomerSegment entities from DB.
The code of other entities:
public class NetworkNHMapped : ModelEntity
{
[StringLength(50)]
public virtual string Name { get; set; }
public virtual int NetworkOwnerId { get; set; }
public virtual int NetworkTypeId { get; set; }
public virtual RepairShop.NetworkType NetworkType { get { return (RepairShop.NetworkType)NetworkTypeId; } }
}
public class NetworkNewMap : ClassMap<NetworkNHMapped>
{
public NetworkNewMap()
{
Table("Network");
Id(x => x.Id, "NetworkId");
Map(x => x.Name, "NetworkName");
Map(x => x.NetworkOwnerId, "NetworkOwnerId");
Map(x => x.NetworkTypeId, "NetworkType");
}
}
And base ModelEntity:
public virtual int Id { get; set; }
public override int GetHashCode()
{
if (!IsPersisted())
{
return base.GetHashCode();
}
unchecked
{
int result = GetObjectRealType(this).GetHashCode();
result = 42 * result + Id.GetHashCode();
return result;
}
}
public override bool Equals(object other)
{
if (ReferenceEquals(this, other))
{
return true;
}
if ((other == null) || !(other is ModelEntity))
{
return false;
}
var thisType = GetObjectRealType(this);
var otherType = GetObjectRealType(other);
if (thisType != otherType)
return false;
if (Id.Equals(default(long)) && (other as ModelEntity).Id.Equals(default(long)))
{
return base.Equals(other);
}
return Id == (other as ModelEntity).Id;
}
public static bool operator ==(ModelEntity entity1, ModelEntity entity2)
{
var obj1 = (object)entity1;
if (obj1 == null && ((object)entity2) == null)
return true;
return obj1 != null && entity1.Equals(entity2);
}
public static bool operator !=(ModelEntity entity1, ModelEntity entity2)
{
return !(entity1 == entity2);
}
public virtual bool IsPersisted()
{
return Id > 0;
}
protected static Type GetObjectRealType(object obj)
{
return (obj is INHibernateProxy) ? NHibernateUtil.GetClass(obj) : obj.GetType();
}
}