我在 MVC4 中有一个简单的模型,它将两个 CRM 产品实体链接在一起。CRM 实体是由 CrmSvcUtil.exe 生成的早期绑定类,模型为:
namespace Demo.Models
{
public class ProductLink
{
public int Id { get; set; }
[ForeignKey("ProductSource")]
[Display(Name = "Product Source")]
public Guid? SourceId { get; set; }
public virtual Xrm.Product ProductSource { get; set; }
[ForeignKey("ProductTarget")]
[Display(Name = "Product Target")]
public Guid? TargetId { get; set; }
public virtual Xrm.Product ProductTarget { get; set; }
}
}
当我尝试添加控制器时,我得到:
无法检索“Demo.Models.ProductLink”的元数据。在模型生成期间检测到一个或多个验证错误:
- System.Data.Entity.Edm.EdmEntityType: : EntityType 'RelatedEntityCollection' 没有定义键。定义此 EntityType 的键。
- System.Data.Entity.Edm.EdmEntityType: : EntityType 'EntityCollection' 没有定义键。定义此 EntityType 的键。
- System.Data.Entity.Edm.EdmEntityType: : EntityType 'Relationship' 没有定义键。定义此 EntityType 的键。
- System.Data.Entity.Edm.EdmEntitySet: : EntityType: EntitySet 'RelatedEntityCollections' 基于没有定义键的类型'RelatedEntityCollection'。
- System.Data.Entity.Edm.EdmEntitySet: : EntityType: EntitySet 'EntityCollections' 基于没有定义键的类型'EntityCollection'。
- System.Data.Entity.Edm.EdmEntitySet: : EntityType: EntitySet 'Relationships' 基于没有定义键的类型'Relationship'。