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

Add parameterless overload of HasDefaultValueSql #7872

Closed
ajcvickers opened this issue Mar 14, 2017 · 1 comment
Closed

Add parameterless overload of HasDefaultValueSql #7872

ajcvickers opened this issue Mar 14, 2017 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Member

HasDefaultValueSql does two things:

  • It tells Migrations what to set on the column.
  • It tells the update pipeline that there is default for the column so that it can do the correct thing on inserts.

If you are managing the database outside of EF, then the first point doesn't apply, but you still need to pass in some string, even though this is then ignored by the update pipeline. This has always seemed a bit clunky. Instead we could allow a parameterless call to be made:

modelBuilder.Entity<Blog>()
        .Property(b => b.Created)
        .ValueGeneratedOnAdd()
        .HasDefaultValueSql();

I think this looks pretty nice in the fluent API and is less clunkly than passing some random string.

If this is used with Migrations/EnsureCreated, it could throw, or maybe it could just default to using null for the default value.

/cc #4189

@ajcvickers
Copy link
Member Author

Design meeting notes:

  • We decided to do this as described, except use the HasDefaultValue() method rather than the HasDefulatValueSql() because the latter says "there is a default value of some form" without it necessarily being SQL.

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
@ajcvickers ajcvickers modified the milestones: Backlog, 2.0.0 Jun 9, 2017
ajcvickers added a commit that referenced this issue Jul 2, 2017
… passing null or no arguments

Issues #8015, #7872

Setting null or passing no args to the fluent API now sets a sentinel indicating that the method has been called rather than removing the annotation. In most cases the result is functionally equivalent, but in some cases it will now force non-identity value generation without the need to specify what is actually happening in the database.
ajcvickers added a commit that referenced this issue Jul 3, 2017
… passing null or no arguments

Issues #8015, #7872

Setting null or passing no args to the fluent API now sets a sentinel indicating that the method has been called rather than removing the annotation. In most cases the result is functionally equivalent, but in some cases it will now force non-identity value generation without the need to specify what is actually happening in the database.
ajcvickers added a commit that referenced this issue Jul 3, 2017
… passing null or no arguments

Issues #8015, #7872

Setting null or passing no args to the fluent API now sets a sentinel indicating that the method has been called rather than removing the annotation. In most cases the result is functionally equivalent, but in some cases it will now force non-identity value generation without the need to specify what is actually happening in the database.
@ajcvickers ajcvickers modified the milestones: 2.0.0, Backlog Jul 3, 2017
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

1 participant