[6.80.341] Issue with Code First and insert statements
Posted: Mon 16 Apr 2012 10:10
Hi!
I've been experiencing very annoing issue.
I've many-to-many relation between my two entities (both of them have abstract base classes) and the relation is mapped in both configurations for entities.
The main entity (MedicalService) config:
The child entity (Icd9Extension) config:
My problem is that every time I create new MedicalService entity with existing in context child (existing Icd9Extension entity) I'm getting an exception. With dbMonitor help I managed to establish that first executing insert statement is the insert into many-to-many linking table so I've got missing reference exception because there is no parent element. I suppose that the second insert would try to insert the parent element.
Could You please help me with this issue ?
I've been using
6.8.341 oracle dotConnect
Entity Framework 4.1[/code]
I've been experiencing very annoing issue.
I've many-to-many relation between my two entities (both of them have abstract base classes) and the relation is mapped in both configurations for entities.
The main entity (MedicalService) config:
Code: Select all
HasMany(t => t.Icd9Components).WithMany(m => m.MedicalServices).Map(m =>
{
m.MapLeftKey("SERVICE_ID");
m.MapRightKey("PROCEDURE_ID");
});
Code: Select all
HasMany(t => t.MedicalServices).WithMany(t => t.Icd9Components).Map(m =>
{
m.MapLeftKey("PROCEDURE_ID");
m.MapRightKey("SERVICE_ID");
});
Code: Select all
using (var context = new DomainContext())
{
var data = context.Icd9Extensions.ToList();
var newData = new MedicalServiceEntity
{
Icd9Components = new List()
};
newData.Icd9Components.Add(data[0]);
context.MedicalServices.Add(newData);
context.SaveChanges();
}
I've been using
6.8.341 oracle dotConnect
Entity Framework 4.1[/code]