Is a request to a newly added object possible in the MS Entity Framework

Is there a way to query or just access a newly added object (using the ObjectContext.AddObject method) in the Entity Framework? I mean a situation when it has not yet been saved to the data warehouse using SaveChanges

I understand that queries are translated into basic SQL and run against a data warehouse, and it does not yet have this new object. But, in any case, I am curious - if this is not justified, perhaps this is possible in theory. If this is not the case, how can a developer handle this? Manually track new objects and query them using Linq for objects?

The same question applies to LinqToSql.

+5
source share
2 answers

In EF, if you use this code, you have all the entities that are already loaded into the context (including new ones):

context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Unchanged).Select(o => o.Entity).OfType<YourObjectType>()
+7
source

"The same question applies to LinqToSql."

For LINQ-to-SQL, see DataContext.GetChangeSet(); these are 3 separate collections for pending .Inserts, .Updatesand.Deletes

Note that ChangeSetthis is a snapshot when the method is called GetChangeSet(); You need to re-request additional changes.

+2
source

All Articles