Entity Framework - avoiding another query

Posted by adamjellyit on Stack Overflow See other posts from Stack Overflow or by adamjellyit
Published on 2010-06-16T21:44:47Z Indexed on 2010/06/16 21:52 UTC
Read the original article Hit count: 354

Filed under:

I have a requirement to only save data to a table in a database (I don't need to read it)

If the record already exists I want to update it otherwise I will add it. It usually exists.

My entity context might already hold the object .. if it does I want to find it and use it again without causing it to refresh from the database when I 'find' it

i.e. The context holds a collection of entities (rows of a database) I want to find an entity in the collection and only want the context to go to the database if entity is not in the collection. I don't care about the current values of the entity .. I just want to update them.

Hope this is clear ..... thanks

© Stack Overflow or respective owner

Related posts about entity-framework