Created
September 18, 2014 09:08
-
-
Save ianfnelson/bc68505f4054c491d130 to your computer and use it in GitHub Desktop.
Snippet for 2010 blog post "NHibernate and Mapping Aggregates"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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