Is it possible to get Entity Framework to recognize objects that have been created and not yet saved in database?

Add the created and unsaved objects to a List o.GetType() == typeof(Object1Type) && o => o.Name. Contains("hello")) .FirstOrDefault() the docs.

Add the created and unsaved objects to a List then filter that list with linq like you did above. EDIT: actually, I stand corrected. It looks like you can specify merge options on the ObjectContext.TestDBEntities.

ObjectStateManager. GetObjectStateEntries(EntityState. Added) .

Where(o => o.GetType() == typeof(Object1Type) && o => o.Name. Contains("hello")) .FirstOrDefault(); the docs.

– stirfry Jun 19 at 2:08 @david : your thing does work so it's good to at least know there is a solution. I still think it's a little cumbersome. I found another question (stackoverflow.

Com/questions/815586/…) which I might try to implement, although I'm not sure how out of date it is as the SaveChanges overload it uses has been deprecated. – stirfry Jun 19 at 2:35 @stickman: you can always override SaveChanges and handle it however you like. Also, feel free to give me some credit if the answer is correct :)!

– David Wick Jun 19 at 2:39 @David : Yeah I'm new to EF so I didn't realize there was SaveChanges and AcceptAllChanges so I'm figuring out what the difference is. Looks like there is a way to have some sort of SQL Transaction type thing. – stirfry Jun 19 at 2:46 Its NOT a transaction - all regular queries hit the database, and ignore local changes, however, EF4.1 provides an easy way to query those local changes - (and EF4.0 provides a more complicated one) – Andiih Jun 19 at 11:03.

I'm a bit late here... @DavidWicks answer doesn't tell the whole story! The context does provide a mechanism to query - and it got a lot easier in EF4.1 than 4.0 In 4.1 take a look at msdn.microsoft.com/en-us/library/gg69624...).aspx the dbSet. Local property holds all of the local changes for objects (that have not been deleted) in the context, so querying against that is all you need!

1 I wish they would hurry up and finish/improve the docs for 4.1; so hard to find relevant info. – David Wick Jun 19 at 11:09 this is probably a stupid question, I just installed EF4.1 - how do I use this Local property? My "TestDBEntities" class is an ObjectContext where the Local property seems to exist in the DbSet class.

Please note, I generated the domain model from the database. – stirfry Jun 19 at 13:40 blogs.msdn. Com/b/adonet/archive/2010/12/06/… - Really should've read a book about this before just leaping right into EF4.So you have to generate an EDMX file and then you got to generate another file if you want it in a DbContext?

Why didn't they just include the whole thing in one step? – stirfry Jun 19 at 13:51 Books - checkout Programming Entity Framework by Julia Lerman. The 2nd Edition is EF4 (not 4.1) – Andiih Jun 19 at 17:41 Re @stickmans one step question - think of the EDMX as an engine+API.

The DbContext is kindof an 3rd party add-on written against the API, if you don't want it, don't use it, if a different one better meets your needs, use that etc... – Andiih 10/12/068 at 11:53.

Then currObj will return the first object I created. This is because that object is in the database. I'm creating a large batch process and I don't want to save everything to the database until the end.

However, I have to do checks like make sure a certain object hasn't already been added etc. which require me to reference these objects before they have been saved to the database. Is it possible to make LINQ queries in Entity Framework that can be aware of objects that are in memory which have not been saved to database.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions