Entity Framework Core 2.0: Error Does not contain a definition for UseSqlServerIdentityColumn

前端 未结 1 1896
借酒劲吻你
借酒劲吻你 2021-01-06 11:34

I am writing this for an identity column in Entity Framework Core 2 with SQL Server, and getting this error

Propertybuilder does not contain a definit

1条回答
  •  时光说笑
    2021-01-06 12:00

    In EF Core 2.0, the syntax has changed a bit. This method should now work:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {    
      modelBuilder.Entity(b =>
      {
        b.HasKey(e => e.Identifier);
        b.Property(e => e.Identifier).ValueGeneratedOnAdd();
      }
    }
    

    My guess is this was done so that the same method could be used across storage providers (not just SQL Server).

    Largely copied from similar answer here: https://stackoverflow.com/a/35847279/2343739

    0 讨论(0)
提交回复
热议问题