没有定义键。在实现具有 Id 的接口时定义此 EntityType 的键
No key defined. Define the key for this EntityType when implementing interface that has Id
我想在我的 EF Code First 业务对象中实现 Dev Express IResource 中定义的接口。
public class JResource : IResource , IXafEntityObject
{
[Key]
public int IdKey { get; set; }
[NotMapped]
public object Id => IdKey; // since IResource wants this.
// other properties
}
当我 运行 我的应用程序创建数据库时出现错误,我需要为此 EntityType 定义键。
我认为问题在于 EF 希望将 Id 视为键,但我将 Id NotMapped 设置为 NotMapped 因为我希望它是一个 Int 而接口希望它是一个对象。
有解决办法吗?
原来我对 [Key] 属性使用了错误的引用。
正确的是
System.ComponentModel.DataAnnotations.KeyAttribute
我想在我的 EF Code First 业务对象中实现 Dev Express IResource 中定义的接口。
public class JResource : IResource , IXafEntityObject
{
[Key]
public int IdKey { get; set; }
[NotMapped]
public object Id => IdKey; // since IResource wants this.
// other properties
}
当我 运行 我的应用程序创建数据库时出现错误,我需要为此 EntityType 定义键。
我认为问题在于 EF 希望将 Id 视为键,但我将 Id NotMapped 设置为 NotMapped 因为我希望它是一个 Int 而接口希望它是一个对象。
有解决办法吗?
原来我对 [Key] 属性使用了错误的引用。 正确的是
System.ComponentModel.DataAnnotations.KeyAttribute