Skip to content

Instantly share code, notes, and snippets.

@skoon
Created March 16, 2011 19:45
Show Gist options
  • Save skoon/873165 to your computer and use it in GitHub Desktop.
Save skoon/873165 to your computer and use it in GitHub Desktop.
So this is what I had to do to get a composite key to work
public class ScrewturnPageKeyword
{
private int? _hashCode;
public virtual string Page { get; set; }
public virtual string Namespace { get; set; }
public virtual int Revision { get; set; }
public virtual string Keyword { get; set; }
public override bool Equals(object obj)
{
if (obj == null) return false;
if (this == obj) return true;
var pk = obj as ScrewturnPageKeyword;
return (this.Page == pk.Page
&& this.Namespace == pk.Namespace
&& this.Keyword == pk.Keyword);
}
public override int GetHashCode()
{
if (!_hashCode.HasValue)
_hashCode = base.GetHashCode();
return _hashCode.Value;
}
}
public class PageKeywordMappings : ClassMap<ScrewturnPageKeyword>
{
public PageKeywordMappings()
{
Table("PageKeyword");
CompositeId()
.KeyProperty(m => m.Page)
.KeyProperty(m => m.Keyword)
.KeyProperty(m => m.Namespace);
Map(m => m.Revision);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment