我已经在Ef Core模型中定义了这个类,用于SQLite。
现在我的问题是,当我尝试运行Add-Migration时,会抛出错误。
如何在 EF Core 模型中为 SQLite 添加主键? 编辑1:模型生成器
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.
如何在 EF Core 模型中为 SQLite 添加主键? 编辑1:模型生成器
public class MyContext : DbContext
{
public DbSet<Ejercicios> Ejercicios { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=MyDb.db");
}
}