Search code examples
entity-frameworkentity-relationshipforeign-key-relationshipordbms

One-to-one relationship in Entity Framework without PK or EntityKey


I have an one-to-one relationship in my SQL database but when i generate a model in entity framework it will changes to one-to-many relationship :`(

My foreign key field haven`t pk but have an unique index.

have somebody there any idea?

Photo: http://share.pho.to/7I7XQ


Solution

  • I see what you mean but there doesn't seem to be any reason to have the person table at all. Are there people who are persons who are NOT patients in your schema? There usually isn't a one to one relationship between tables usually. I'm not sure if that relationship detection would even be built into a tool. If you have persons who are not patients it seems you can have it in the patients table with null values for the rest and maybe even an "active" column for answering if they are actively being treated. All database concerns being satisfied its more efficient to have as few tables as possible.