I have classes
public abstract class Content : IContent { public virtual Guid Id { get; protected set; } public virtual IPage Parent { get; set; } public virtual DateTime Created { get; set; } } public abstract class Page : Content, IPage { public virtual string Slug { get; set; } public virtual string Path { get; set; } public virtual string Title { get; set; } } public class Foo : Page, ITaggable {
And as a result, I would like to have the following tables. I tried to implement many different IConventions, but even hierarchy mappings (table for abstraction-hierarchy / table for specific subclass) seem to fail.
Content Id Type (discriminator) ParentId Created Slug Path Title Content_Tags (Tags from ITaggable) ContentId TagId Content$Foo Bar Content$Foo_Related ParentFooId ChildPageId
I already have ugly, working smooth mappings, but I would like to get rid of some ugliness
public class ContentMapping : ClassMap<Content> { public ContentMapping() { Table("Content"); Id(x => x.Id).GeneratedBy.GuidComb(); References<Page>(x => x.Parent, "ParentId"); Map(x => x.Created); DiscriminateSubClassesOnColumn("Type"); } } public class PageMapping : SubclassMap<Page> { public PageMapping() { Map(x => x.Slug); Map(x => x.Path); Map(x => x.Title); } } public class ConcreteContentMapping<T> : SubclassMap<T> where T : Content, new() { public ConcreteContentMapping() : this(true) { } protected ConcreteContentMapping(bool mapJoinTable) { DiscriminatorValue(typeof(T).FullName); MapCommonProperties(); if(mapJoinTable) { MapJoinTableWithProperties(CreateDefaultJoinTableName(), GetPropertiesNotFrom(GetContentTypesAndInterfaces().ToArray())); } } private void MapCommonProperties() { if (typeof(ITagContext).IsAssignableFrom(typeof(T))) { Map(x => ((ITagContext)x).TagDirectory); } if (typeof(ITaggable).IsAssignableFrom(typeof(T))) { HasManyToMany(x => ((ITaggable)x).Tags).Table("Content_Tags").ParentKeyColumn("ContentId").ChildKeyColumn("TagId").Cascade.SaveUpdate(); } }
How to get the same result with AutoCorrect?
source share