[英]Set Default value in field Entity Framework Core
I need to set this by Fluent API and I`ve read documentation.我需要通过 Fluent API 进行设置,并且我已经阅读了文档。 There is HasDefaultValue() method should I use.我应该使用 HasDefaultValue() 方法。 But I can not write it, VS does not give me to do it但是我不会写,VS不给我做
the code below from here documentation下面的代码来自这里的文档
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.Property(b => b.Rating)
.HasDefaultValue(3);
}
Check whether you have installed nuget package Microsoft.EntityframeworkCore.SqlServer
.检查是否安装了 nuget package Microsoft.EntityframeworkCore.SqlServer
。 It has a dependency of Microsoft.EntityframeworkCore.Relational
whixh has the HasDefaultValue()
extension它依赖于Microsoft.EntityframeworkCore.Relational
whixh 具有HasDefaultValue()
扩展
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.