Closed jasonlaw closed 3 years ago
yes, that's all looks like it behaves as expected. The deleted Voter entity, although marked as Fantom, is still stuck in the internal ref lists (poll.Voters). This is a compromise, to provide you with convenient auto-loaded lists of linked entities, but at the same time, when you delete an entity, the system does NOT run thru all loaded entities and internal lists removing it. In the case like yours I think the best approach is to build response from a new session. Like this: delete entity; session.SaveChanges; abandon session, open session2, retrieve entity by Id, build the response etc.
Thanks for the clarification and suggested solution!
Hi @rivantsov ,
I have the entity model schema as following, where a Poll can have multiple PollOption, and each PollOption can have multiple PollVoter.
In my case, when I retracted the vote by deleting the PollVoter from the PollOption, the record is successfully removed from DB, and the deleted PollVoter entity is marked as phantom.
In this case, when I try to check if I have any voter for the Poll or PollOption, I would expect no more voter since the only voter has been deleted. However, the linq query still returning me the phantom entity and the system would thought there is still a voter there, which is wrong.
I have tried EntityHelper.Refresh but still the same problem. I have also tried to query back the Poll entity by using EntitySet, again still the same problem.
Is this a bug? Otherwise, any way to reset the entity?