How to insert new objects in EF?
Let's say I have 2 context with the same structure and I am updating data from one context to another.
Somewhere updated, and the need to put in a brand new data from the preceding context with the preservation Id.
Actually a question:
For example, in the context of destination already has a User object that has a Request object, and that, in turn, refers to the collection RerquestData.
It turns out that I to the existing User need to insert additional data.
I must notify EF that I need to do is insert and not update(id!=0) or he is smart and he should handle it?
Now, I choose from the context of the destination User in the Request object create a new collection, which copy data from the source.
However, when you save the swearing:
Database operation expected to affect 1 row(s) but actually affected 0 row(s)
If you download the debug symbols and descend into the depths of EF, I see that he's trying to do the update by ID, which is not present in the database and I wanted to insert.
asked April 19th 20 at 12:00
If you need to replicate a dB, for many there are ready-made solutions.
Find more questions by tags Entity FrameworkC#