【发布时间】:2012-03-15 22:32:31
【问题描述】:
我正在尝试在以下对象之间创建多对多关系:
public class Classified{
[Key]
public int Id {get;set;}
public string details {get;set;}
public ICollection<ClassifiedRating> Ratings {get;set;}
}
public class User{
[Key]
public int Id {get;set;}
public string Name {get;set;}
}
public class ClassifiedRating{
[Key]
public User Rater {get;set;}
[Key]
public Classified Classified {get;set;}
public int rating {get;set;}
}
我在运行时收到以下错误:
One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ClassifiedRating'
has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'ClassifiedRating'
is based on type 'RateUser' that has no keys defined.
(“\t”也出现在错误消息中,虽然我怀疑它是否相关,但有点奇怪......)
【问题讨论】:
标签: c# entity-framework many-to-many ef-code-first data-annotations