开发者

Create Entity Associations on Non Key Columns

I have two tables Users and Schools. Each have primary keys and no foreign keys. The database I have to tie in has no normalization at all, but I still have to have associations in it. I noted some other questions that were similar, but I couldn't quite understand what they were asking, so sorry if this is a repeat.

Users Table
UserId int NON NULL
School varchar NON NULL

Schools Table
SchoolId int NON NULL
SchoolNa开发者_开发问答me varchar NON NULL

The data looks like this:

Users Table
UserId    School
1         ABC
2         ABC

Schools Table
SchoolId  SchoolName
1         ABC
2         DEF

The association I would like to create is below, with the key being the SchoolName in the Schools table and the School in the Users table

User *--1 School


Unfortunately this is not possible. If you want to do this in the database you will mark SchoolName in Schools table as unique (by placing unique constraint / index) and because of that you will be able to build one-to-many relation. EF doesn't support unique keys any because of that you cannot define such association neither in database (it will not be reflected in your model) or in the model directly by referential constraints.

When working with EF the good database design is still the key.


As a FYI to someone having a similar issue, Linq to SQL does have this ability and it appears to work just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜