我无法在表中插入记录
public class KPITable
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string Query { get; set; }
public string TableName { get; set; }
}
public class KPITableMap : EntityTypeConfiguration<KPITable>
{
public KPITableMap()
{
ToTable("EIS_KPI", AppUtility.EISMDBSchemaName);
Property(t => t.Id).HasColumnName("KPI_ID");
Property(t => t.Name).HasColumnName("NAME").HasMaxLength(20);
Property(t => t.Query).HasColumnName("QUERY").HasMaxLength(20);
Property(t => t.TableName).HasColumnName("TABLE_NAME").HasMaxLength(20);
}
}
当我尝试添加新实体时出现错误
为类型为“EISM.Database.Models.KPITable”的不可为空的成员“Id”返回了一个空的存储生成值
var newEntity = new KPITable();
newEntity.Id = 55;
newEntity.Name = data.Name;
newEntity.Query = data.Query;
newEntity.TableName = data.TableName;
_dbContext.KPIs.Attach(newEntity);
_dbContext.Entry(newEntity).State = EntityState.Added;
_dbContext.SaveChanges();