2

Not a very experienced EF guy so thought I would ask the experts on this one.

I have an entity call "Applicant". An Applicant can have many "Applications".

I have a typical method that searches for an Applicant. If the Applicant exists it is updated, else it is added. At the same time a new Application is added in both cases.

I have 2 ways I can do this:

1) Create or Update the Applicant and create an Application separately immediately afterwards. 2) Create or Update the Applicant but add the Application to the Applications Collection (of the Applicant).

The question I have relates to option 2. When I retrieve an Applicant from the database and it exists, I then add my new Application to its collection. When I update the Applicant does it do an update for each item in its collection or is it intelligent enough to know I've only added 1 new Application? In other words, am I making unecessary round trips to the database?

Hope it makes sense.

Using EF 4.3.1.

Thanks in advance.

dotnetnoob
  • 9,233
  • 17
  • 51
  • 92
  • Already discussed here [try this][1] [1]: http://stackoverflow.com/questions/5557829/update-row-if-it-exists-else-insert-logic-with-entity-framework – Niventh Feb 25 '13 at 11:23

1 Answers1

1

No it doesn't update every existing item in the collection. It will only send the new item you've added to the collection.

For a better view of what sql queries EF is sending you may want to look at using an ORM profiler.

Your options are EFProf or OrmProfiler

Or if you want to skip paid options you could use linqpad or Sql Server Profiler tool (if you have a non express version of sql server to achieve the same.

scartag
  • 16,927
  • 3
  • 44
  • 50