Question

I have this situation:

public namespace ANamespace
{
    public abstract class ABase:IABase
    {
        //properties
    }

    public abstract class A : ABase
    {
        //properties
    }

    public class A1 : A
    {
        //properties
    }

    public class A2 : A
    {
        //properties
    }
}

If I use this mapping code:

AutoMap
   .AssemblyOf<ABase>()
   .Where(e => e.Namespace == "ANamespace")
   .IncludeBase<A>().IgnoreBase<ABase>();

only A table is created (with ABase and A properties). If I delete IncludeBase() then A1 and A2 are created (with all properties).

AutoMap
   .AssemblyOf<ABase>()
   .Where(e => e.Namespace == "ANamespace")
   .IgnoreBase<ABase>();

How to write mapping to have tables for classes A (with all A and ABase properties), A1 and A2 (with specific properties) in my database but not for the class ABase?

Était-ce utile?

La solution

After three days I finally found solution to this problem. It's not enough to have IncludeBase<T>(). You have to map base class too. So the solution is:

AutoMap
  .AssemblyOf<ABase>()
  .Where(type=>type.IsSubclassOf(typeof(A)) || type==typeof(A))
  .IncludeBase<A>();

I hope it will help some similar problems...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top