question

Rene-4203 avatar image
0 Votes"
Rene-4203 asked karenpayneoregon commented

Unexpected result

I have a process that is processing a list of coordinates. It does this in batches. Let say it's processing 100 coordinates in batches of 10. So I have a foreach loop over with my 100 coordinates and every 10th I do a SaveChanges().

Within the loop I'm checking to see if the coordinate is a duplicate. If so, I mark it as deleted by setting a flag.

If it's not a duplicate I'm searching for the previous coordinate (in time) that is not deleted.

Now the unexpected part of my case: often times the coordinate I get back from this method has it's deleted flag to true!

If I, after setting the deleted flag, do a SaveChanges(), I get a different result.

Who can explain this difference in behaviour? Is this a bug or by design?

I'm using
EF 5.0.0
.net framework 4.5

dotnet-entity-framework
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @Rene-4203

One thing you can do to better understand is to read the documentation on SaveChanges/SaveChangesAsync and track changes along with implementing logging as shown in this DbContext.


0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi Rene-4203,
The SaveChanges method return the number of rows affected.
When you set the deleted flag, it means this row was changed.
So the number returned will be affected by the number of deleted flags you set.
If I misunderstand what you mean, please correct me and explain it in detail or provide some relevant code snippets.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.