views:

41

answers:

1

Hi

I am long time user of LINQ2SQL, but have not used the Entity Framework yet.

One thing that is not possible in LINQ2SQL is to use tracked entities in different data contexts, or 'link' objects from different data contexts.

Example:

Foo f = null;

using (var dc = new DB()) 
  f = dc.Foos.Single(x => x.ID = 1);

using (var dc = new DB()) 
{
  var b = new Baz();
  dc.Bazs.InsertOnSubmit(b);
  f.Baz = b;
  dc.SubmitChanges();
}

Note: IIRC, this can work if using disconnected objects (but IMO that is pretty useless).

Today, I saw an article on EF4 implying that the pattern above can be used with EF4.

So the question is: Is this in fact possible?

+1  A: 

no you cannot

you stil lhave to faff about with detaching and attaching to a new data context. Invariably you end up doing this by using the unique key for the object to slect it out of the database and then copy the properties into the new object and save the changes back.

Sad but true.

I used to be a lin2sql junkie, i do prefer EF4 though after a bit of exposure to it. I like the various forms of inheritance - they can be leveraged to do some interesting things.

John Nicholas
Thanks, I havent had the opportunity to use it yet.
leppie