Foreign key to Asp.net user
I am currently making a model class and for one of the fields I would like to make a foreign key referencing to the id of a user in the asp.net user table, but I am not sure how and have tried to look on google.
10 Replies
Just do
This will be easiest, using a navigation property and the
...Id
convention to tell EF this property stores the ID
(TKey
being the type of the key, ofc)Yeah but the user table is autocreated by asp.net
so Im not sure what type mycooluser is
So?
Ah
IdentityUser
Oh I see
And the ID type will be
string
, I believealright I think I got it then
thanks
should be this right?
Or just name your nav property
Author
and get rid of the attribute
If you have a property Foo
, then a property FooId
will be automatically set to store the foreign key
No need for any additional configOh I see
thanks
will this work if I need a second fk to the same table
since I cant use User again
bet, thanks