【发布时间】:2020-01-05 05:21:05
【问题描述】:
我在 Ef Core Model for SQLite 中定义了这个类。
public class Ejercicios : BaseModel
{
private int _TipoEjercicio;
[Key]
public int TipoEjercicio
{
get { return _TipoEjercicio; }
set { SetProperty(ref _TipoEjercicio, value); }
}
private string _DescripcionEjercicio;
public string DescripcionEjercicio
{
get { return _DescripcionEjercicio; }
set { SetProperty(ref _DescripcionEjercicio, value); }
}
private string _HexForeColor;
public string HexForeColor
{
get { return _HexForeColor; }
set { SetProperty(ref _HexForeColor, value); }
}
private string _HexBackGroundColor;
public string HexBackGroundColor
{
get { return _HexBackGroundColor; }
set { SetProperty(ref _HexBackGroundColor, value); }
}
}
现在我的问题是当我尝试运行 Add-Migration 时,会抛出
System.InvalidOperationException: The entity type 'Ejercicios' requires a primary key to be defined.
如何为 sqlite 的 EF Core 模型添加主键?
编辑 1: 模型生成器
public class MyContext : DbContext
{
public DbSet<Ejercicios> Ejercicios { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=MyDb.db");
}
}
【问题讨论】:
标签: c# entity-framework