Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascade Support #12

Closed
mguinness opened this issue Dec 10, 2019 · 5 comments
Closed

Cascade Support #12

mguinness opened this issue Dec 10, 2019 · 5 comments

Comments

@mguinness
Copy link

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 in AspNetUserRoles is orphaned.

@morrisjdev
Copy link
Owner

Hi.

Good point. I will take a look if this is easily possible and will write you soon.

Thank you

@mguinness
Copy link
Author

Thanks Morris, I appreciate you looking into this.

@mguinness
Copy link
Author

@morrisjdev Were you able to investigate and see the level of difficulty involved?

@morrisjdev
Copy link
Owner

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

@mguinness
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants