Question

I've entity type called 'Question', when i create new instance of it and add it to entity set 'Questions' (using AddObject()), than call SaveChanges() method on context, all works fine. But when i added it, but not call SaveChanges() yet and try to execute some linq against 'Questions' the query result not contain recently added 'Question' object, it seems invisible for linq until SaveChanges() is called. This is a correct behavior or i miss something?

Was it helpful?

Solution

I believe this is correct behaviour, especially if you are referring to Entity Framework.

This should be able to get objects that you have added before save changes is called ie once you have added them:

ObjectStateManager.GetObjectStateEntries 

msdn ref

OTHER TIPS

For simplicity i decide not to use LINQ but use Count() method to see how many question objects i have after AddObject()

(_context.Questions.ToArray()).Count()

got 8

// defaultQuestion object initialization here ...
_context.Questions.AddObject(defaultQuestion);
(_context.Questions.ToArray()).Count()

again got 8

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top