I played with EntityFramework CTP4 and decided to apply it to one of my current projects. The application uses the SQLServer database and there is one table with a composite key. Say the MyEntity table has Key1 and Key2 as foreign keys (individually) and as a composite primary key.
I created a configuration class derived from EntityConfiguration:
class MyEntityConfiguration : EntityConfiguration<MyEntity> { public MyEntityConfiguration() { HasKey(m => m.Key1); HasKey(m => m.Key2); } }
Then in my DataContext (derived from DbContext):
public DbSet<MyEntity> MyEntities { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new MyEntityConfiguration()); }
The problem is that when I request "MyEntities" for all of my posts:
var entities = from e in MyModel.Instance.MyEntities select e;
I get a really strange result, consisting of the first record repeated 18 times, then the second one is repeated 18 times (for a record, my table has 36 records).
I suspect that the problem is related to the composite key, since no other entity shows this problem.
Any help would be appreciated, thanks :)
c # composite-key entity-framework-4
DrunkenBeard Jul 21 2018-10-21T00: 00Z
source share