【问题标题】:EntityType has no key defined. Define the key for this EntityTypeEntityType 没有定义键。定义此 EntityType 的键
【发布时间】:2017-10-20 17:22:12
【问题描述】:

我有一个简单的 WCF 服务项目,我已向其中添加了实体框架。如您所见,Entity 类看起来不错。但是,当我运行该项目时,我遇到了奇怪的异常EntityType 'AccountOperationEntity' has no key defined. Define the key for this EntityType. 我以前从未遇到过这样的问题。有人可以解释一下发生了什么吗?我创建的所有类都出现此异常。

public class AccountOperationEntity
{
    [Key]
    public uint Id { get; set; }
    public virtual AccountEntity Account { get; set; }
    public OperationType OperationType { get; set; }
    public float Amount { get; set; }
    public DateTime DateTime { get; set; }
}

当我尝试enable-migrations 时也会发生这种情况。

【问题讨论】:

  • @KasunjithBimal 不应该没有 [Table] 工作吗?

标签: c# entity-framework wcf


【解决方案1】:

实体框架不支持 Uint 作为键。

https://entityframework.codeplex.com/workitem/1489

【讨论】:

  • 谢谢,这对我来说真的很神秘。错误应该说类似“uint not supported”。
猜你喜欢
  • 2016-04-02
  • 2016-03-16
  • 2013-08-04
  • 2012-12-10
  • 2016-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多