Skip to content

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

Closed
roji wants to merge 2 commits intomasterfrom
IdentityFluentApi
Closed

Draft for SQL Server identity fluent API in model snapshot#21210
roji wants to merge 2 commits intomasterfrom
IdentityFluentApi

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

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 roji force-pushed the IdentityFluentApi branch from 858c121 to 9c02c00 Compare June 18, 2020 23:04
@roji roji closed this Jun 18, 2020
roji added a commit that referenced this pull request Jun 18, 2020
@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