Closed mguinness closed 4 years ago
Hi.
Good point. I will take a look if this is easily possible and will write you soon.
Thank you
Thanks Morris, I appreciate you looking into this.
@morrisjdev Were you able to investigate and see the level of difficulty involved?
Hi @mguinness.
Sorry for the late reply. I was very busy in the last days.
I found the origin of the problem:
FileContextCore uses a kind of lazy loading. That means that data are only loaded when they are needed. If you have data with references the referenced data are only loaded when you explicitly use .Include(...)
.
If you delete data without loading the references FileContextCore never knows that there are data that have to get deleted too.
In a relational database there are additional constraints that are defined on database side to avoid that problem but FileContextCore does not have them.
To use that feature you always have to make sure to load referenced data.
This for example works:
db.Users.RemoveRange(db.Users.Include(u => u.Entries));
db.SaveChanges();
Again sorry for the long response time.
Best regards.
Morris
No problem Morris, thanks for taking the time to investigate. This appears to be a similar issue to Cascade Delete Support in the InMemory provider.
Thanks for creating this library which is great for demos and using this in IdentityManagerUI repo. Do you have any plans to support Cascade Delete? This causes issues since if a role in
AspNetRoles
is deleted then corresponding record inAspNetUserRoles
is orphaned.