Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // INTERFACES
- public interface ISingleCategorized
- {
- Category Category { get; set; }
- }
- public interface IMultiCategorized
- {
- IList<Category> Categories { get; set; }
- }
- public interface IPage
- {
- int Id { get; }
- string Path { get; set; }
- IPage Parent { get; set; }
- }
- public interface ISearchablePage : IPage
- {
- string SearchIndex { get; set; }
- }
- public interface ISingleCategorizedPage : IPage, ISingleCategorized
- {
- }
- public interface IMultiCategorizedPage : IPage, IMultiCategorized
- {
- }
- // ENTITY CLASSES
- public abstract class Page : IPage
- {
- public virtual int Id { get; set; }
- public virtual IPage Parent { get; set; }
- public virtual string Path { get; set; }
- [Searchable]
- public virtual string Title { get; set; }
- }
- public class Post : Page, ISearchablePage, IMultiCategorizedPage, IMultiTaggedPage
- {
- [Searchable]
- public virtual string Text { get; set; }
- // IMultiCategorizedPage
- public virtual IList<Category> Categories { get; set; }
- // IMultiTaggedPage
- public virtual IList<Tag> Tags { get; set; }
- string ISearchablePage.SearchIndex { get; set; }
- public Post()
- {
- Categories = new List<Category>();
- Tags = new List<Tag>();
- }
- }
- public class Article : Page, ISearchablePage, ISingleCategorizedPage, IMultiTaggedPage
- {
- [Searchable]
- public virtual string Text { get; set; }
- // ISingleCategorizedPage
- public virtual Category Category { get; set; }
- // IMultiTaggedPage
- public virtual IList<Tag> Tags { get; set; }
- string ISearchablePage.SearchIndex { get; set; }
- public Article()
- {
- Tags = new List<Tag>();
- }
- }
- // FLUENT NHIBERNATE MAPPING CLASSES
- public class PageMapping : ClassMap<Page>
- {
- public PageMapping()
- {
- Table("Page");
- Id(x => x.Id,"Id");
- References<Page>(x => x.Parent, "ParentId");
- Map(x => x.Path, "Path");
- Map(x => x.Title, "Title");
- DiscriminateSubClassesOnColumn("Type");
- }
- }
- public class PostMapping : SubclassMap<Post>
- {
- public PostMapping()
- {
- Map(x => x.Text, "Text");
- // IMultiCategorizedPage
- HasManyToMany(x => x.Categories).Table("PageCategories").ParentKeyColumn("PageId").ChildKeyColumn("CategoryId").Cascade.SaveUpdate();
- // IMultiTaggedPage
- HasManyToMany(x => x.Tags).Table("PageTags").ParentKeyColumn("PageId").ChildKeyColumn("TagId").Cascade.SaveUpdate();
- // ISearchablePage
- Map(x => ((ISearchablePage)x).SearchIndex, "SearchIndex").LazyLoad();
- }
- }
- public class ArticleMapping : SubclassMap<Article>
- {
- public ArticleMapping()
- {
- Map(x => x.Text, "Text");
- // ISingleCategorizedPage
- References(x => x.Category, "CategoryId");
- // IMultiTaggedPage
- HasManyToMany(x => x.Tags).Table("PageTags").ParentKeyColumn("PageId").ChildKeyColumn("TagId").Cascade.SaveUpdate();
- // ISearchablePage
- Map(x => ((ISearchablePage)x).SearchIndex, "SearchIndex").LazyLoad();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement