none
Inserting New Object with Relation to Cached (pre-loaded) Object RRS feed

  • Question

  • Picture a cached set of data objects, a list of Countries. Now imagine creating a new Address using your DataContext and linking newAddress.Country = cachedCountry. You have your Address being created on your current DataContext, but the cachedCountry is from a seperate (now non-existant) DataContext. This produces the "an attempt to attach an entity..." error upon calling SubmitChanges(). My current work around is to reload the country from the current DataContext before attaching it to the new Address object. But this makes it pointless to even cache the countries if I have to reload them anyway.

    Is there a better way?

    Thanks!

    Thursday, April 29, 2010 9:53 PM

Answers

All replies