Entity Framework - Mapping 1 to Many
-
Hello, Forgive if this is in the wrong forum. I didn't see a better one to use. i'm confused on the mapping of a 1 to many. I have 1 table with a primary key of userid. I have another table with the primary key of userid and authid. I created an association of a 1 to many (because one user record to many occurrances of security authorizations for that user). When I assign userid to userid - that's fine but obviously I don't have a match for authid -> and the compiler isn't happy about that. So how does 1 to many work or am I missing something :omg: - in order to have a many, the primary key can't match because it 2nd tables record's primary key has to be unique? Any help would be appreciated. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
-
Hello, Forgive if this is in the wrong forum. I didn't see a better one to use. i'm confused on the mapping of a 1 to many. I have 1 table with a primary key of userid. I have another table with the primary key of userid and authid. I created an association of a 1 to many (because one user record to many occurrances of security authorizations for that user). When I assign userid to userid - that's fine but obviously I don't have a match for authid -> and the compiler isn't happy about that. So how does 1 to many work or am I missing something :omg: - in order to have a many, the primary key can't match because it 2nd tables record's primary key has to be unique? Any help would be appreciated. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
-
Hello, Forgive if this is in the wrong forum. I didn't see a better one to use. i'm confused on the mapping of a 1 to many. I have 1 table with a primary key of userid. I have another table with the primary key of userid and authid. I created an association of a 1 to many (because one user record to many occurrances of security authorizations for that user). When I assign userid to userid - that's fine but obviously I don't have a match for authid -> and the compiler isn't happy about that. So how does 1 to many work or am I missing something :omg: - in order to have a many, the primary key can't match because it 2nd tables record's primary key has to be unique? Any help would be appreciated. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
I would guess that your composite primary key is incorrect. Ask this question, can a user have multiple types of authorisations. If yes then you need a many to many link User - UserID Authorisation - AuthID Link - LinkID - unique constraint (userid/authid) I hate composite primary keys - personal bias only!
Never underestimate the power of human stupidity RAH
-
I would guess that your composite primary key is incorrect. Ask this question, can a user have multiple types of authorisations. If yes then you need a many to many link User - UserID Authorisation - AuthID Link - LinkID - unique constraint (userid/authid) I hate composite primary keys - personal bias only!
Never underestimate the power of human stupidity RAH
Thank you for your reply. Yes, a person can have 1-N authorizations. I guess i'm still confused with 1 to many in this context. From the user record, I wanted to include the auths table to get at the auths relating to that person. In order to have a 1 to many, the 2nd table must have an additional field(s) defined as the primary key for uniqeness. But EF seems to want a matching of 1-1 of primary keys. Not sure how that's can be. Unless there's something about the mapping I completely am overlooking. Nathan
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous