-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Update guidance on using default values #1398
Comments
Should setting default values in the parameter-less constructor of the underlying class also be an option? For example: class MyContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
}
public class Blog
{
public Blog()
{
Rating = 3;
}
public int BlogId { get; set; }
public string Url { get; set; }
public int Rating { get; set; }
} |
@Sergey-Nosov-GH Can you give some details on why this is preferable to: public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public int Rating { get; set; } = 3;
} |
@ajcvickers those are functionally equivalent, so your example would be fine. Nether is currently in the docs, and that is confusing. I came to this discussion from the following url: https://docs.microsoft.com/en-us/ef/core/modeling/relational/default-values As of right now, it has no mentions of defaults set on the underlying classes; and it makes the programmer wonder, if EF overrides such defaults, goes along with them, or what happens. Thus, more guidance would be helpful. Thank you. |
@Sergey-Nosov-GH Yes, this issue is for adding more guidance here. See the link in the issue content above for a link to a discussion on this. I thought you were commenting on this discussion, where this pattern is covered. |
Oh, yes. These discussions have at least two interfaces for adding comments: one on GitHub and one as the Feedback feature on the live documentation site. As such visitor comments on the docs site end up on GitHub as well. So, basically, just adding another vote for more examples of different ways to set defaults; the docs site is currently limited to HasDefaultValue and HasDefaultValueSql methods only. Documentation feedback, in action. LOL |
See discussion here: dotnet/efcore#15070 (comment)
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: