Reputation: 2167
In my hierarchy of animals
Base one:
public class AnimalMap : ClassMap<Animal>
{
public AnimalMap()
{
Schema("dbo");
Table("Animals");
Id(x => x.Id).Column("ID").GeneratedBy.Identity();
Map(x => x.FoodClassification).Column("FoodClassification");
Map(x => x.BirthDate).Column("BirthDate");
Map(x => x.Family).Column("Family");
DiscriminateSubClassesOnColumn("ClassType").Not.Nullable();
}
}
One subclass:
public class DogMap : SubclassMap<Dog>
{
public DogMap()
{
DiscriminatorValue(@"Dog");
Map(x => x.Field).Column("Field");
}
}
So the question is:
Where column "ClassType" != Dog , Animal should be object type, like base one. Each one who has no mapping class should have base(super) one.
How to make it works?
Upvotes: 0
Views: 626
Reputation: 30803
important: only do this to support legacy schemas and animal is readonly
public class SomeAnimal : Animal
{
}
public class AnimalMap : ClassMap<Animal>
{
public AnimalMap()
{
Schema("dbo");
Table("Animals");
Id(x => x.Id).Column("ID").GeneratedBy.Identity();
Map(x => x.FoodClassification).Column("FoodClassification");
Map(x => x.BirthDate).Column("BirthDate");
Map(x => x.Family).Column("Family");
DiscriminateSubClassesOnColumn().Formula("IIF(classtype = 'dog', 'dog', 'someAnimal')");
}
}
public class SomeAnimalMap : SubclassMap<SomeAnimal>
{
public SomeAnimalMap()
{
ReadOnly();
DiscriminatorValue("someAnimal");
Map(x => x.ClassType).Column("classtype");
}
}
Upvotes: 1