不包含“HasDefaultValue”的定义

Abh*_*del 3 c# entity-framework-core .net-core ef-core-2.2

我想首先在代码中为不可为空的字段设置默认值。

我已经包括Microsoft.EntityFrameworkCore但我仍然得到

不包含“HasDefaultValue”的定义

使用 EF Core 2.2.6

using Microsoft.EntityFrameworkCore;

public partial class MyDbContext : DbContext
{
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Agency>(entity =>
        {
                entity.HasOne(d => d.Region)
                    .WithMany(p => p.Agencies)
                    .HasForeignKey(d => d.RegionId)
                    .HasDefaultValue(1)
                    .HasConstraintName("FK_Agency_Region");
        });
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

Sam*_*ath 6

EF 核心 6+

我的问题是我没有将此包添加到我的存储库项目中:

https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Relational/

PM> Install-Package Microsoft.EntityFrameworkCore.Relational 
Run Code Online (Sandbox Code Playgroud)