EF Code First not generating table for ICollection

前端 未结 4 666
旧时难觅i
旧时难觅i 2020-12-07 01:28

I would like the below ICollection property in one of my data classes (let\'s call it \"Foo\")

public class Foo
{
    [Key]
    public int FooId { get; set;          


        
4条回答
  •  既然无缘
    2020-12-07 01:55

    EF can only work with entity classes. Each entity class must have defined primary key so the minimum in your scenario is:

    public class StringData
    {
        public int Id { get; set; }
        public string Data { get; set; }
    }
    

    or worse

    public class StringData
    {
        [Key]
        public string Data { get; set; }
    }
    

    Now you can define collection of StringData to map it as related table:

    public virtual ICollection AllowedBars { get; set; }
    

提交回复
热议问题