1
外鍵我有點使用實體框架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);
}
而且我得到這個錯誤:
Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.ICollection'. An explicit conversion exists (are you missing a cast?)
我試圖刪除接口,一切都很好..
有幫助嗎?
謝謝
我明白了。謝謝! – Davide