Skip to content

Instantly share code, notes, and snippets.

@ianfnelson
Created September 18, 2014 09:08
Show Gist options
  • Save ianfnelson/bc68505f4054c491d130 to your computer and use it in GitHub Desktop.
Save ianfnelson/bc68505f4054c491d130 to your computer and use it in GitHub Desktop.
Snippet for 2010 blog post "NHibernate and Mapping Aggregates"
public class IdeaMap : ClassMap<Idea>
{
public IdeaMap()
{
Id(x => x.Id)
.Column("ID")
.GeneratedBy.Identity();
Map(x => x.Summary).Not.Nullable();
Map(x => x.Description).WithMaxSize().Not.Nullable();
Map(x => x.Created).Not.Nullable();
Map(x => x.LastStatusChange).Not.Nullable();
Map(x => x.Visible).Not.Nullable();
Map(x => x.Status).Not.Nullable();
Map(x => x.CommentCount)
.Formula("(select count(*) from Comment c where c.IdeaId = ID)");
HasMany(x => x.Votes).KeyColumn("IdeaId")
.Inverse().Cascade.AllDeleteOrphan();
HasMany(x => x.Comments).KeyColumn("IdeaId")
.Cascade.All();
References(x => x.Category).Column("CategoryId")
.Not.Nullable();
References(x => x.CreatedBy).Column("UserId")
.Not.Nullable();
Cache.ReadWrite();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment