I'm trying to make a login AUTH with C# .NET but I'm getting this error and can't solve it.
Here is my code.
User class
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
RegisterDTO
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
IUserRepository
public class UserRepository : IUserRepository
{
private readonly ApiDbContext _context;
public UserRepository(ApiDbContext context)
{
_context = context;
}
public User Create(User user)
{
_context.Users.Add(user);
user.UserId =_context.SaveChanges();
return user;
}
}
And the error I'm getting is when I start Swagger and trying to post username email and password:
SqlException: Cannot insert explicit value for identity column in table 'Users' when IDENTITY_INSERT is set to OFF.