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

DeleteBehaviorAttribute #9621

Closed
John0King opened this issue Aug 30, 2017 · 6 comments · Fixed by #27630
Closed

DeleteBehaviorAttribute #9621

John0King opened this issue Aug 30, 2017 · 6 comments · Fixed by #27630
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Milestone

Comments

@John0King
Copy link

Data annotations is a much easier way to configure model than Fluent API.
And we can only configure DeleteBehavior via Fluent API today, that means we need configure foreign key again in fluent api.
Can we have a DeleteBebaviorAttribute(DeleteBehavior behavior) in Microsoft.EntityFramework Namespace ?

@John0King John0King changed the title Add a DeleteBehaviorAttribute data annotations Can we have a DeleteBehaviorAttribute Aug 30, 2017
@ajcvickers ajcvickers added this to the Backlog milestone Aug 30, 2017
@ajcvickers ajcvickers added the help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. label Aug 30, 2017
@John0King
Copy link
Author

see also in #10864

@divega divega added good first issue This issue should be relatively straightforward to fix. help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. and removed help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. good first issue This issue should be relatively straightforward to fix. labels May 31, 2019
@ajcvickers ajcvickers added good first issue This issue should be relatively straightforward to fix. and removed help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. labels Aug 5, 2019
@smitpatel smitpatel removed the good first issue This issue should be relatively straightforward to fix. label Sep 18, 2019
@ajcvickers ajcvickers added area-model-building good first issue This issue should be relatively straightforward to fix. labels Jun 22, 2020
@Vekz
Copy link
Contributor

Vekz commented Mar 10, 2022

Hey, I've wanted to take on the challange of implementing this.
This would've been my first ever issue done in open source community so please be understanding.

As far as I understand I should create DeleteBehaviorAttribute class in EFCore.Abstractions taking DeleteBehavior parameter in constructor (for now I've used int as I have trouble getting DeleteBehavior usings to EFCore.Abstractions) and storing it as a property.
And also create DeleteBehaviorAttributeConvention in EFCore/Metadata/Conventions and register it in ProviderConventionSetBuilder.

Could someone explain to me also how could I reference DeleteBehavior enum from inside of EFCore.Abstractions?

@ajcvickers
Copy link
Contributor

@Vekz Sounds like a good plan. For the enum, move it to Abstractions and add type-forwarding to avoid a breaking change. For an example, search for TypeForwardedTo in the EF source.

@Vekz
Copy link
Contributor

Vekz commented Mar 11, 2022

Okay, I've finished writing tests and figuring out how to put everything I've learned in past day so every case works.
And I managed to succeed.

Only this enum's left for me to implement. I'm gonna make PR probably later today. Thanks for really fast reply and pointing me to the solution.

@Vekz
Copy link
Contributor

Vekz commented Mar 11, 2022

I didn't think I would get so much trouble from this TypeForwarding.

I get CS0012 on tests that build models from snapshot after I've done TypeForwarding.
Should I just add EFCore.Abstractions assembly reference to the test builder?

Sorry if it's stupid question this is actually first time I've ever touched TypeForwarding.

Update: I just added EFCore.Abstractions assembly reference in Bases for snapshot and migration tests and it fixed it

@Vekz
Copy link
Contributor

Vekz commented Mar 19, 2022

@ajcvickers Could I ask you for a CR?
I know you are probably busy with other tasks and I don't expect PR being merged as it's not the most urgent feature on the list for sure.
But I would love to hear your feedback does the code meet all requirements or could I've done something better.

@AndriySvyryd AndriySvyryd added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution labels May 18, 2022
@AndriySvyryd AndriySvyryd modified the milestones: Backlog, 7.0.0 May 18, 2022
AndriySvyryd pushed a commit that referenced this issue May 18, 2022
Fixes #9621

Added:
DeleteBehaviorAttribute - Stores DeleteBehavior set on the property.
DeleteBehaviorAttributeConvention - Triggers on ForeignKeyAdded, checks if its navigation has DeleteBehavior. If so then sets DeleteBehavior of this foreign key.

Moved:
DeleteBehavior => EFCore.Abstractions and added TypeForward in EFCore
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview5 May 25, 2022
@ajcvickers ajcvickers changed the title Can we have a DeleteBehaviorAttribute DeleteBehaviorAttribute Jun 23, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview5, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants