Abstract base class and inheritance
I have an abstract base class and would like to be able to inherit from this class in multiple step e.g create a second abstract base class that inherits from the first and then inherit the second and so on.
I'm using the automapping feature but have figured out how to setup the mappings correct.
This is how it looks today with:
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ShowSql()
.ConnectionString(c => c.FromConnectionStringWithKey("conn")))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<ContentItem>()
.AddEntityAssemblys(x => x.AssembliesFromApplicationBaseDirectory())
.Where(t => t.IsSubclassOf(typeof(ContentItem)))
.Setup(s => {
s.IsDiscriminated = type => true;
s.DiscriminatorColumn = type => "type";
s.SubclassStrategy = type => SubclassStrategy.Subclass;
})
))
So how can I write the where statement if I would like to be able to have a chain of inheritance from contentitem?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by James Gregory on 04 Mar, 2010 01:20 PM
Do you want your abstract base classes to be represented in the database? Or are they simply layer-supertype's that just contain shared implementation details?
If it's the latter, then you'll need to use the
IgnoreBase<T>()
method to tell the automappings to ignore those base classes.3 Posted by marcus on 04 Mar, 2010 03:00 PM
ContentItem is represented in the database so
IgnoreBase<T>()
does not work for me.This is an example of how I use my code
Support Staff 4 Posted by James Gregory on 12 Mar, 2010 09:49 AM
You're going to have to give me some more to work with here. What database structure do you desire? What are your current mappings producing?
We've established
ContentItem
will be stored in the database. What aboutBasePage
? Are these all going to be stored in the same table, or do you want them split table-per-subclass?5 Posted by marcus on 12 Mar, 2010 11:01 AM
Yes ContentItem will be stored in the database. I decorate all members with a custom attribute to decide if they should be mapped and this is my mappings for that.
.OverrideAll(o => o.IgnoreProperties(p => p.DeclaringType.GetCustomAttributes(typeof(ContentDetailAttribute), false).Length <= 0))
My members on the entites that inherit ContentItem will not be automapped so I use the Details collection to save my properties to the database in a table called ContentDetail.
I have figured out that if my BasePage not is abstract I will get the result I want so i guess this is not any problem for me anymore. I hope you understand what I try to discribe :)
James Gregory closed this discussion on 24 Mar, 2010 08:59 AM.