4.0: Extending User Entity
Right now, our User
entity is very simple - it is only has the id, username, and password hash/salt for our users.
Let's add some more information for each of our users.
Adding More Properties to User.cs
Update User.cs
inside of your .Data/Entities
folder to:
We'll also want to add photos for our users - so let's create a new entity to represent them.
Adding Photo.cs
Inside of your .Data/Entities
folder, add a new class called Photo.cs:
This class has a Foreign Key of UserId
that will connect each Photo
to the User
with the matching Id.
It also has a navigation property of User
- which will be an object of the user with the Foreign Key. This will aid in querying.
Adding Photo navigation property to User
Now, we'll make use of our new Photo
entity and add a navigation property of Photo
to our User.cs
class.
This time it will be a collection of Photos - because we want our User to have more than one photo (one-to-many relationship).
Database Diagram
Here's what our current relationship looks like.
It's a one-to-many relationship between User
(one) and Photos
(many).
As we continue our application, this will get more interesting as we add more tables and many-to-many relationships.
Last updated