0

I have the following domain model to map using ClassMaps/SubclassMaps

A - HasMany -> B (A should be table)

B is abstract in code (and should not be a table)

C,D,E inherits B and all have very different properties. Each of them should be a table with foreign key to A.

I get the tables I want, but I cannot see how to map HasMany from entity A that has one property IList<B> SomeProperty

I would like to define in ClassMap<A> that SomeProperty cascades on C,D,E

This obviously doesn't work, in ClassMap<A>:

HasMany<C>(x => x.B).Cascade.All();

HasMany<D>(x => x.B).Cascade.All();

HasMany<E>(x => x.B).Cascade.All();

As I cannot duplicate B.

Example:

public class Person
{
   public virtual IList<Animal> Animals { get; set; }

  public void AddAnimal(Animal animal)
  {
     Animals.Add(animal);
  }
}

public abstract class Animal
{
//some common properties
}

public class Cat : Animal
{
//some cat properties
}
public class Horse : Animal
{
//some horse properties
}

In this case I would like ClassMap<Person> to map to Cat and Horse over the abstract class Animal.

Islandwind
  • 143
  • 2
  • 8

1 Answers1

0
Try...

public void AddAnimal(Animal animal)
{
    animal.Person = this; //Recomended 
    Animals.Add(animal);
}


public abstract class Animal
{
     public virtual Person Person {get;set;} //Recomended Addition
//some common properties
}
  • You are correct, the code was missing in my example, but it will still not work as Animal will want to have its own ClassMap (which I don't want). I have a solution where all the sub classes of 'Animal' are mapped to 'Person 'until something better comes up. – Islandwind Feb 08 '12 at 09:28