bob
bob

Reputation: 611

EF6 not generating foreign key associations

My question is a follow-on to EF6 Does not generate foreign key association from database but that answer was not sufficient to resolve my issue. I am using VS 2013 update 4/EF 6/SQL Server 2014.

In my case users represent linux accounts and have the following structure:

Original DB Schema

Where Accounts.Username and Groups.Name are primary keys and there are unique indexes on Accounts.UID and Groups.GID. These are related through the GroupMembership table. EF creates:

Original Model

No associations. Interestingly, when I change the Primary Keys: Updated DB Schema

So that Accounts.UID and Groups.GID become the primary keys and Accounts.Username and Groups.Name have the unique indexes then I get: Updated Model

It appears as though a many-many association will only be created for primary keys. If I try to create one manually in the designer, it won't use my GroupMembership table and I don't know enough to dig in past that.

Of course, I can work around my issue simply enough by using the updated schema but I am trying to improve my EF skills.

Upvotes: 0

Views: 342

Answers (1)

user32826
user32826

Reputation:

It wouldn't surprise me at all if EF won't use varchar columns for keys...

Upvotes: 0

Related Questions