views:

310

answers:

1

I am using link to sql, I have a connected set of objects.

I start out and do a linq statement like this

Dim L= from II in context.InventoryItems select II
Dim L2 = L.tolist

The second line was so that I could narrow down where the problem was occuring. When the second line is hit I get an error "The EntitySet is already loaded and the source cannot be changed"

Any ideas what might be causing this?

+1  A: 

Omer's comment brings up a very good point: is this DataContext being re-used from a previous operation? If so, you may want to check out Dino Esposito's blog post regarding lifetime of the DataContext to make sure you're not keeping it around too long.

That error sounds like maybe you have already loaded data from the InventoryItems table using that DataContext and possibly made some changes to entities bound to the DataContext that you have not yet submitted. If you try your code with a brand new DataContext without specifying any special DataLoadOptions it should work.

Matt V