LINQ to Entities / SQL - Way of seeing what is attached to object context?
Bit of an odd question but is there a way of seeing what objects are attached to my object context. I am getting a few random problems and it would really be helpful to solve them if i could see w开发者_开发技巧hat's been attached and not yet saved through "SaveChanges".
Answer (Entity Framework) : context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Unchanged).Select(o => o.Entity).OfType<YourObjectType>();
Maybe I'm misunderstanding (or oversimplifying) your question but it sounds like GetChangeSet() could help you?
I think this article might be of interest.
It covers using reflection to look inside (private) fields in the DataContext for changed items. I believe it could be adapted to show all items, not just changed ones.
You look at the object state entries in the ObjectStateManager. This article has an example.
精彩评论