I am new to fluent NHibernate. Now I face one problem with mapping composite keys. Can anyone point out the URL or sample please?
Another thing to note is that you must override the Equals and GetHashCode methods for an entity using a CompositeId. Given the accepted answers mapping file, your entity would look like this.
public class Entity
{
public virtual int Something {get; set;}
public virtual AnotherEntity SomethingElse {get; set;}
public override bool Equals(object obj)
{
var other = obj as Entity;
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return other.SomethingElse == SomethingElse && other.Something == Something;
}
public override int GetHashCode()
{
unchecked
{
return (SomethingElse.GetHashCode()*397) ^ Something;
}
}
}