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

Draft for SQL Server identity fluent API in model snapshot #21210

Closed
wants to merge 2 commits into from

Conversation

roji
Copy link
Member

@roji roji commented Jun 10, 2020

@bricelam this is some quick draft work on #16922:

  • Add new API to IAnnotationCodeGenerator to receive all annotations, allowing generating a single fluent API call for several annotations. Fully backwards-compatible.
  • Implement handling for seed/increment via the new API
  • Plumb IAnnotationCodeGenerator into CSharpSnapshotGenerator and use it to generate fluent API calls.
  • Note: this currently removes annotations that are identified as by-convention by IAnnotationCodeGenerator from the context snapshopt - I'm guessing that's probably not good (since conventions may change across EF Core versions). If that's the case we should simply split IAnnotationCodeGenerator API - one for removing by-convention annotations, and another for generating fluent API calls.
  • If we go down this route, we can just remove all the older IsHandledByConvention/GenerateFluentApi methods from the interface (but not from the base class), since we no longer call them directly.

If this looks like a good direction, let me know and I'll continue.

@roji roji requested a review from bricelam June 10, 2020 15:19
@@ -524,6 +524,8 @@ protected virtual void GeneratePropertyAnnotations([NotNull] IProperty property,

var annotations = property.GetAnnotations().ToList();

// First, handle built-in annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// First, handle built-in annotations
// First, handle non-provider-specific annotations

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Jun 12, 2020

Note: this currently removes annotations that are identified as by-convention by IAnnotationCodeGenerator from the context snapshopt - I'm guessing that's probably not good (since conventions may change across EF Core versions). If that's the case we should simply split IAnnotationCodeGenerator API - one for removing by-convention annotations, and another for generating fluent API calls.

Yes, we should do this. Otherwise it's looking good (though more elaborate than I imagined it)

We should also consider using IAnnotationCodeGenerator to remove the annotations that are never generated - #15675

@bricelam
Copy link
Contributor

+1 Looks good. Just need a way of generating by-convention annotations in the snapshot. Maybe a bool in HandleAnnotations()?

@roji
Copy link
Member Author

roji commented Jun 12, 2020

@bricelam

Just need a way of generating by-convention annotations in the snapshot. Maybe a bool in HandleAnnotations()?

I actually thought of just exposing two APIs - one which removes annotations which are by convention (called when scaffolding but not when generating the snapshot), and one which removes annotations for which a fluent API exists (and returns the fluent API calls).

@AndriySvyryd

Otherwise it's looking good (though more elaborate than I imagined it)

Did I over-engineer? Any ideas for simplifying?

should also consider using IAnnotationCodeGenerator to remove the annotations that are never generated

Will do this too.

@AndriySvyryd
Copy link
Member

Did I over-engineer? Any ideas for simplifying?

My initial design was just passing the string builder to the provider, but your way is better.

@roji
Copy link
Member Author

roji commented Jun 18, 2020

Superceded by #21329

@smitpatel smitpatel deleted the IdentityFluentApi branch June 18, 2020 23:45
roji added a commit that referenced this pull request Jun 20, 2020
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

Successfully merging this pull request may close these issues.

3 participants