我对使用 Entity Framework 5 有点困惑。我为我的实体创建了两个接口:
然后我创建了如下类:
单词:
public class Word : IWord
{
[Key]
[Required]
public int WordId { get; set; }
[Required]
public string Tag { get; set; }
[Required]
public string Translation { get; set; }
[Required]
public char Language { get; set; }
public string Abbreviation { get; set; }
//Foreign Key
public int VocabularyId { get; set; }
//Navigation
public virtual IVocabulary Vocabulary { get; set; }
}
词汇:
public class Vocabulary : IVocabulary
{
[Key]
[Required]
public int VocabularyId { get; set; }
[Required]
public string Name { get; set; }
public virtual List<IWord> Words { get; set; }
}
最后,我在DataContext
我的文章中写道:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Word>()
.HasRequired(w => w.Vocabulary)
.WithMany(v => v.Words)
.HasForeignKey(w => w.VocabularyId)
.WillCascadeOnDelete(false);
base.OnModelCreating(modelBuilder);
}
我收到了这个错误:
无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.ICollection”。存在显式转换(您是否缺少演员表?)
我试图删除接口,一切都很好..
有什么帮助吗?
谢谢