I want to add Users to my database Using DB Set but I am collecting only information about the Username and the password how can I add without UserID?
This is my constructor:
public class User
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(30)]
public string Username { get; set; }
[Required]
[MaxLength(30)]
public string Password { get; set; }
public List<Note> Notes { get; set; }
public User(string username, string password)
{
this.Id = 1;
this.Username = username;
this.Password = password;
}
And this is my Adding method:
User user = new User(username, password);
UserContext.Users.Add(user);
UserContext.SaveChanges();
When I execute my code the database is still empty.