运行所选代码生成器时发生错误:“找不到主键”。

时间:2020-04-01 22:14:00

标签: c# entity-framework asp.net-core asp.net-core-webapi

当尝试使用“使用实体框架的带有操作的API控制器”添加脚手架控制器时,出现错误:

运行选定的代码生成器时发生错误:“找不到主键。”

出于目的,我的模型没有任何ID,因此我向HasNoKey()函数添加了调用,但仍然收到上述错误。

这是我的模特

 public class Tag
 {
     public DateTime DateTimeRef { get; set; }
     public double Data { get; set; }
 }

这是我的上下文类:

public class TagContext : DbContext
{
    public TagContext(DbContextOptions<TagContext> options)
        : base(options)
    {
    }

    public DbSet<Tag> Tags { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Tag>(e => { e.HasNoKey(); });
    }
}

0 个答案:

没有答案