Entity Framework Is it possible to add an ASSOCIATION between Primary Keys and a Foreign Key

后端 未结 2 1575
盖世英雄少女心
盖世英雄少女心 2021-01-13 00:55

I\'ve got the following entities on my EDMX :- \"alt

These two entites were generated by Update Mode

2条回答
  •  灰色年华
    2021-01-13 00:59

    For proper DB normalization, first thing is that primary keys must be only CountryId and StateId fields - the main Id fields for each table.

    And ss I see from the description Name & IsoCode and Name & CountryId should be actually Unique keys, not primary.

    Then the model class State should have a field:

    public Country Country { get; set; }
    

    Now EF have very good examples and since 4.3.1 + it fully supports Code first / DB first models, which I think will ease solving this. EF 5 have more compatibility updates so I think it wont be a problem for legacy DB engines.

提交回复
热议问题