The following model:
``` c#
public class Gear2
{
public int Id { get; set; }
public virtual ICollection<Weapon> Weapons { get; set; }
}
public abstract class Weapon
{
public int Id { get; set; }
}
public class HeavyWeapon : Weapon
{
public bool Overheats { get; set; }
}
public class StandardWeapon : Weapon
{
}
public class GearsModel : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// uncomment the line below and it works
//modelBuilder.Entity<Weapon>();
modelBuilder.Entity<Gear2>().HasMany(g => g.Weapons).WithMany().MapToStoredProcedures();
}
}
```
produces these view-gen validation errors:
> (13,10) : error 3034: Problem in mapping fragments starting at lines 13, 24:Two rows with different primary keys are mapped to the same entity. Ensure these two mapping fragments do not map two groups of entities with identical keys to two overlapping groups of rows.
> (13,10) : error 3034: Problem in mapping fragments starting at lines 13, 30:Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with different keys to two overlapping groups of rows.
> (13,10) : error 3034: Problem in mapping fragments starting at lines 13, 19:Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with different keys to the same group of rows.
> (24,10) : error 3034: Problem in mapping fragments starting at lines 19, 24:Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with different keys to two overlapping groups of rows.
> (30,10) : error 3034: Problem in mapping fragments starting at lines 19, 30:Two rows with different primary keys are mapped to the same entity. Ensure these two mapping fragments do not map two groups of entities with identical keys to two overlapping groups of rows.
I narrowed the problem down to a Code First mapping configuration ordering issue. In the repro above, if the Weapon class is explicitly registered (see commented line), then a valid model is created.
Comments: Could you please let me know if this is fixed in EF6?
``` c#
public class Gear2
{
public int Id { get; set; }
public virtual ICollection<Weapon> Weapons { get; set; }
}
public abstract class Weapon
{
public int Id { get; set; }
}
public class HeavyWeapon : Weapon
{
public bool Overheats { get; set; }
}
public class StandardWeapon : Weapon
{
}
public class GearsModel : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// uncomment the line below and it works
//modelBuilder.Entity<Weapon>();
modelBuilder.Entity<Gear2>().HasMany(g => g.Weapons).WithMany().MapToStoredProcedures();
}
}
```
produces these view-gen validation errors:
> (13,10) : error 3034: Problem in mapping fragments starting at lines 13, 24:Two rows with different primary keys are mapped to the same entity. Ensure these two mapping fragments do not map two groups of entities with identical keys to two overlapping groups of rows.
> (13,10) : error 3034: Problem in mapping fragments starting at lines 13, 30:Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with different keys to two overlapping groups of rows.
> (13,10) : error 3034: Problem in mapping fragments starting at lines 13, 19:Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with different keys to the same group of rows.
> (24,10) : error 3034: Problem in mapping fragments starting at lines 19, 24:Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with different keys to two overlapping groups of rows.
> (30,10) : error 3034: Problem in mapping fragments starting at lines 19, 30:Two rows with different primary keys are mapped to the same entity. Ensure these two mapping fragments do not map two groups of entities with identical keys to two overlapping groups of rows.
I narrowed the problem down to a Code First mapping configuration ordering issue. In the repro above, if the Weapon class is explicitly registered (see commented line), then a valid model is created.
Comments: Could you please let me know if this is fixed in EF6?