Consider the following model:
```
public abstract class Creature
{
public int Id { get; set; }
}
public abstract class Animal : Creature
{
public bool IsCute { get; set; }
}
public class Herbivore : Animal
{
public string FavoritePlant { get; set; }
}
public class Carnivore : Animal
{
public string FavoriteAnimal { get; set; }
}
public class Human : Creature
{
public string Name { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Creature> Creatures { get; set; }
}
```
It is not possible to create this in the designer (__abstract__ class Animal and __concrete__ class Human inheriting from class Creature).
The designer reports the following error:
Error 3032: Problem in mapping fragments starting at lines 54, 80:EntityTypes YADB.Carnivore, YADB.Herbivore, YADB.Human are being mapped to the same rows in table Creatures. Mapping conditions can be used to distinguish the rows that these types are mapped to.
Msl fragment in question looks like this:
```
<EntitySetMapping Name="Creatures">
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Creature)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Carnivore)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="FavoriteAnimal" ColumnName="FavoriteAnimal" />
<Condition ColumnName="Discriminator" Value="Carnivore" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Herbivore)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="FavoritePlant" ColumnName="FavoritePlant" />
<Condition ColumnName="Discriminator" Value="Herbivore" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Human)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<Condition ColumnName="Discriminator" Value="Human" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Animal)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="IsCute" ColumnName="IsCute" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
```
There is no problem with this structure, if one uses CodeFirst. Msl in that case looks as follows:
```
<EntitySetMapping Name="Creatures">
<EntityTypeMapping TypeName="YADB.Carnivore">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="IsCute" ColumnName="IsCute" />
<ScalarProperty Name="FavoriteAnimal" ColumnName="FavoriteAnimal" />
<Condition Value="Carnivore" ColumnName="Discriminator" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="YADB.Herbivore">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="IsCute" ColumnName="IsCute" />
<ScalarProperty Name="FavoritePlant" ColumnName="FavoritePlant" />
<Condition Value="Herbivore" ColumnName="Discriminator" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="YADB.Human">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<Condition Value="Human" ColumnName="Discriminator" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.Creature)">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
```
We should make a designer to generate a similar thing, to enable these scenarios.
Comments: Reopening as I believe this is a limitation that would be probably easy to remove and it is also likely one of the main causes of [error 3034 'Two entities with different keys are mapped to the same row'](http://www.bing.com/search?q=error+3034+entity+framework&qs=SC&pq=error3034+&sc=1-10&sp=1&sk=&first=51&FORM=PERE3).
```
public abstract class Creature
{
public int Id { get; set; }
}
public abstract class Animal : Creature
{
public bool IsCute { get; set; }
}
public class Herbivore : Animal
{
public string FavoritePlant { get; set; }
}
public class Carnivore : Animal
{
public string FavoriteAnimal { get; set; }
}
public class Human : Creature
{
public string Name { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Creature> Creatures { get; set; }
}
```
It is not possible to create this in the designer (__abstract__ class Animal and __concrete__ class Human inheriting from class Creature).
The designer reports the following error:
Error 3032: Problem in mapping fragments starting at lines 54, 80:EntityTypes YADB.Carnivore, YADB.Herbivore, YADB.Human are being mapped to the same rows in table Creatures. Mapping conditions can be used to distinguish the rows that these types are mapped to.
Msl fragment in question looks like this:
```
<EntitySetMapping Name="Creatures">
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Creature)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Carnivore)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="FavoriteAnimal" ColumnName="FavoriteAnimal" />
<Condition ColumnName="Discriminator" Value="Carnivore" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Herbivore)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="FavoritePlant" ColumnName="FavoritePlant" />
<Condition ColumnName="Discriminator" Value="Herbivore" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Human)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<Condition ColumnName="Discriminator" Value="Human" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.MyContextModel.Animal)">
<MappingFragment StoreEntitySet="Creatures">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="IsCute" ColumnName="IsCute" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
```
There is no problem with this structure, if one uses CodeFirst. Msl in that case looks as follows:
```
<EntitySetMapping Name="Creatures">
<EntityTypeMapping TypeName="YADB.Carnivore">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="IsCute" ColumnName="IsCute" />
<ScalarProperty Name="FavoriteAnimal" ColumnName="FavoriteAnimal" />
<Condition Value="Carnivore" ColumnName="Discriminator" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="YADB.Herbivore">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="IsCute" ColumnName="IsCute" />
<ScalarProperty Name="FavoritePlant" ColumnName="FavoritePlant" />
<Condition Value="Herbivore" ColumnName="Discriminator" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="YADB.Human">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="Name" ColumnName="Name" />
<Condition Value="Human" ColumnName="Discriminator" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(YADB.Creature)">
<MappingFragment StoreEntitySet="Creature">
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
```
We should make a designer to generate a similar thing, to enable these scenarios.
Comments: Reopening as I believe this is a limitation that would be probably easy to remove and it is also likely one of the main causes of [error 3034 'Two entities with different keys are mapped to the same row'](http://www.bing.com/search?q=error+3034+entity+framework&qs=SC&pq=error3034+&sc=1-10&sp=1&sk=&first=51&FORM=PERE3).