EF Code First not generating table for ICollection

前端 未结 4 671
旧时难觅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:34

    This won't work. The reason for this is, that with relational databases, you can't really save arrays or a collection of things in fields. And since every property in your class will be mapped to a database-field, the only way to collections is via a one to many relationship. So you need the join. So it's not really a limitation of EF, but of relational databases.

    There are people that solve that by saving XML or CSV to string fields in the table. But this is considered very bad style, so don't do it. I recommend you just have to accept the join. It's not hurting anyone anyway.

提交回复
热议问题