C#C
C#2y ago
Gipper

How to create a foreign key pointing to the db table created by ASP.NET Identity (AspNetUsers)?

Hi! I'm making a house listings app for school, using the MVC pattern. Naturally, one of my main db tables is "HouseListings" and naturally one of the columns on that table is UserId and it's supposed to be based on a foreign key pointing to a user ID to associate that particular House Listing to the user that created it. What I wanted to do was avoid creating my own "Users" db table on top of the built in "AspNetUsers" one created automatically when I accepted the Identity schema, so I need to point to that in my HouseListings model class, but obviously AspNetUsers isn't in my Model. From my googling it seems that one can actually bring the Identity models explicitly into my project and work from there, but I don't think that would be necessary. Can I just do a dummy empty class in my Model? Like so:
public class User : IdentityUser
{
}

Thus "bringing in" the AspNetUsers table into my Model and that way I can point to it in my "HouseListings" model class. Would this work? If not how can I make it work to do what I said?
Was this page helpful?