Unexpected result

Rene 1 Reputation point
2020-12-08T10:18:03.52+00:00

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

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,330 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2020-12-09T03:22:14.407+00:00

    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.

    0 comments No comments