Free Nhibernate autopilot with overrides: Match a collection of non-core base classes

Domain:

public class BaseClassClient { public virtual ICollection<BaseClass> BaseObjects{ get; set; } } public abstract class BaseClass { } public class SubClass1 : BaseClass { } public class SubClass2 : BaseClass { } 

I get an Association references unmapped class error message, although both subclasses are displayed. Obviously, the base class is not displayed. Please suggest how to solve this.

Edit

I would prefer that before closing the question as a duplicate to another, they simply do not read, but also need to understand both questions.

I saw the Error: free NHibernate mapping, which refers to a mapping in another assembly . But this is a different scenario.

My script is similar to below.

 public class Product { public int Id { get; set; } public ICollection<BasePricingRule> PricingRules{ get; set; } } public abstract class BasePricingRule { public int Id { get; set; } //other properties } //Several concrete classes inherit from BasePricingRule. 

I want to have one table for a specific class and a table for a base class. Therefore, there is no mapping for BasePricingRule . I allow classes to automatically display, sometimes providing the necessary overrides. I created an automatic override for the product class as shown below.

  public void Override(FluentNHibernate.Automapping.AutoMapping<Product> mapping) { mapping.HasMany(product => product.PricingRules); //Not really sure // about how to map this. } 

I saw examples, for example http://ayende.com/blog/3941/nhibernate-mapping-inheritance for inheritance mappings. But these examples do not actually address the problem I am facing. More than an error, I would like to know how I should map this domain using free NHibernate, preferably using automaton overrides.

+5
source share
1 answer

The fact is that even for the Table Per Concrete Class approach, you have to map the base class. Just not the way you think. You should take a look at this wonderful article: www.codeproject.com/Articles/232034/Inheritance-mapping-strategies-in-Fluent-Nhibernat

It would be something like this:

 public class BaseClassMap : ClassMap<BaseClass> { public BaseClassMap() { // indicates that this class is the base // one for the TPC inheritance strategy and that // the values of its properties should // be united with the values of derived classes UseUnionSubclassForInheritanceMapping(); } } public class SubClass1Map : SubclassMap<SubClass1> { public SubClass1Map() { Table("SubClass1Table"); Abstract(); } } public class SubClass2Map : SubclassMap<SubClass2> { public SubClass1Map() { Table("SubClass2Table"); Abstract(); } } 
0
source

Source: https://habr.com/ru/post/1238172/


All Articles