Andre Silveira

Andre Silveira

  • 1.6k
  • 155
  • 16.1k

Relationship between AspNetUser and my class

Jul 27 2021 6:04 PM

Hello all!

I'm trying to implement Identity and code first on a web application. Let's say I have a table Orders and I want the Id of the user to be in it. How do I declare in my Order class? I've extended the AspNetUser class to my own user class. Would it be like:

public class Order{[Key]
public int Id { get; set; }
public string AspNetUserId { get; set; }
[
ForeignKey("AspNetUserId")]
public MyAppUser User{ get; set; }
}

Do I have to declare the AspNetUserId in order to the entity framework create the field in the database so it is a ForeignKey?

Thank you in advance.


Answers (1)