I’m a bit confused using Entity Framework 5. I created two interfaces for my entities:

Then I created the classes like the following:
Word:
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; }
}
Vocabulary:
public class Vocabulary : IVocabulary
{
[Key]
[Required]
public int VocabularyId { get; set; }
[Required]
public string Name { get; set; }
public virtual List<IWord> Words { get; set; }
}
And at the end, in my DataContext I wrote:
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);
}
And I’m getting this error:
Cannot implicitly convert type ‘System.Collections.Generic.List’ to ‘System.Collections.Generic.ICollection’. An explicit conversion exists (are you missing a cast?)
I tried to remove the Interfaces and everything is fine ..
Any helps?
Thanks
Entity framework cannot handle interfaces in navigation properties. It doesn’t know how to materialize them. So you can keep the interfaces on the types (
class Word : IWordetc.), butVocabulary.Wordsshould be anICollection<Word>.