jka*_*ers 5 c# mysql asp.net entity-framework
只要我有一个带有BIGINT主键的表,就可以插入新记录,但不能更新现有记录。当我尝试进行更新时,出现以下错误:
"The specified value is not an instance of type 'Edm.Decimal'"
样本模型:
public class Model
{
public long ModelID { get; set; }
public DateTime ProcessedOn { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
示例更新代码:
public bool SetModelProcessed(long id)
{
var entity = db.models.SingleOrDefault(m => m.ModelID == id);
entity.ProcessedOn = DateTime.Now;
db.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);
db.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
甚至像这样简单的模型对我来说都是失败的。有人知道发生了什么吗?
编辑
我尝试了代码优先的方法。实体框架4.3甚至无法生成mySQL数据库,这显然是添加了迁移功能后的mySQL和Entity Framework版本的问题。
自降级至版本4.1.10715.0以来long,ulong仍然可以正常运行。如果为,EF不会将属性确认为主键ulong。
EntityType 'Model' has no key defined. Define the key for this EntityType.
我不需要使用long代替来代替ulong,但是我猜必须这样做。
许多年后...在 DbContext 的 OnModelCreating() 方法中使用 HasColumnType("long")。请参阅Entity Framework Core 将不会映射到 BigInteger
| 归档时间: |
|
| 查看次数: |
1014 次 |
| 最近记录: |