views:

46

answers:

0

I've a class like this

class MainClass
{
  AssociatedClass b;
}

It's in a Silverlight RIA solution and the DomainService is LinqToEntitiesDomainService. I've an instance of AssociatedClass called AC and its already in the DB.

Now say I want to create an instance of MainClass on client like this

MainClass MC = new MainClass();
domainContext.MainClasses.Add(MC);
MC.b = AC;

At first it'll work fine. But if in another operation previously there were a reference to AC (like in a datagrid), the last line above will produce

An entity with the same identity already exists in this EntitySet.

Apparently ria thinks that this instance is different from the one that was loaded by the datagrid. And since they share the same ID, above error is generated.

Now I don't know how to tell ria to attach (?) this instance to the other one! Or maybe there is a correct way of loading AC?