C#C
C#14mo ago
Jason

I require some help understanding MVC and Database loading/updating

Hi, I'm very new to MVC and new to ASP.NET CORE, So these questions may be all over the place. I do have an understanding of C# & Object-Oriented programming.

I'm trying to make a web application that has two tables, a
Users
table and a
UserPhoneNumbers
table, for this app I am allowing a single
User
to have Multiple
UserPhoneNumber
attached to it. I understand that I'll need a Model for each.

Here are my two example models
c#
public class User
{
    [Key, Required]
    public string AccountId { get; set; }

    [StringLength(255), Required]
    public string Email { get; set; }
    
    [StringLength(255), Required]
    public string FirstName { get; set; }
    
    [StringLength(255), Required]
    public string LastName { get; set; }
    
    public ICollection<UserPhoneNumber> UserPhoneNumbers { get; set; }
}

public class UserPhoneNumber
{
    [Key, StringLength(32), Required]
    public string? UserPhoneNumberId { get; set; }
    
    [StringLength(32), Required]
    public string? PhoneNumber { get; set; }
    
    public User User { get; set; }

}

Lets presume I have a working database and can perform basic CRUD operations.
Here are my questions:
Was this page helpful?