Persisting details in Master Detail relation EF4 POCO
Posted
by Roger Alsing
on Stack Overflow
See other posts from Stack Overflow
or by Roger Alsing
Published on 2010-05-20T12:41:20Z
Indexed on
2010/05/21
11:50 UTC
Read the original article
Hit count: 472
Scenario: Entity Framework 4 , POCO templates and Master Detail relation.
Lets say I have a master type like this:
//partial implementation of master entity
partial class Master
{
public void AddDetail(x,y,z)
{
var detail = new Detail()
{
X = x,
Y = y,
Z = z,
};
//add the detail to the master
this.Details.Add(detail);
}
}
If I then add a master instance to my context and commit, the details will not be saved:
var masterObject = new Master();
masterObject.AddDetail(1,2,3);
myContext.MasterSet.AddObject(masterObject);
Is there any way to make the details to be persisted by reachabillity when using POCO templates? Or any other way? the Details collection in the Master entity is a FixUpCollection, so it ought to track the changes IMO.
So, any ideas how to make this work W/O killing the POCO'ness too much?
© Stack Overflow or respective owner