EntityTypeBuilder在EF Core中不包含ToTable的定义 [英] EntityTypeBuilder does not contain a definition for ToTable in EF Core
本文介绍了EntityTypeBuilder在EF Core中不包含ToTable的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下示例代码:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Models;
namespace MySampleNamespace
{
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options)
: base(options)
{
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
new UserMap(modelBuilder.Entity<User>());
}
public class UserMap
{
public UserMap(EntityTypeBuilder<User> entityBuilder)
{
entityBuilder.ToTable("User");
entityBuilder.Property(s => s.Username).HasMaxLength(15).IsRequired();
}
}
}
}
I正在从MS网站测试一些示例,但是找不到ToTable方法。在该示例中,我检查了Usings的使用情况,除了使用的模型的类项目之外,Using示例使用的是Microsoft.EntityFrameworkCore。这改变了吗?我现在该怎么办?
I was testing out some example from MS website, but I can't find ToTable method. In the example, I checked what are the Usings and the only Using the example had is Microsoft.EntityFrameworkCore aside from the class project for the model he was using. Was this changed? How do I do this now?
推荐答案
安装 Microsoft.EntityFrameworkCore.Relational
是正确的解决方案,如Ivan所说。
Installing Microsoft.EntityFrameworkCore.Relational
is the correct solution, as Ivan says.
这篇关于EntityTypeBuilder在EF Core中不包含ToTable的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文