문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top