实体框架核心2.0:错误不包含UseSqlServerIdentityColumn的定义 [英] Entity Framework Core 2.0: Error Does not contain a definition for UseSqlServerIdentityColumn

查看:289
本文介绍了实体框架核心2.0:错误不包含UseSqlServerIdentityColumn的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server在Entity Framework Core 2中为标识列编写此代码,并得到此错误

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

Propertybuilder不包含UseSqlServerIdentityColumn的定义

Propertybuilder does not contain a definition for UseSqlServerIdentityColumn

我该如何解决?

推荐答案

在EF Core 2.0中,语法有所变化.此方法现在应该可以工作:

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

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

我的猜测是这样做的,以便跨存储提供程序(而不仅仅是SQL Server)可以使用相同的方法.

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

从类似的答案此处大量复制: https://stackoverflow.com/a/35847279/2343739

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

这篇关于实体框架核心2.0:错误不包含UseSqlServerIdentityColumn的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆