Error: No suitable constructor found for entity type Model. The following parameters could not be bound t
so this will automatically create table in database with these properties, but it's not working, still same error for suitable constructor!, how can i create that constructor correctly, i am using asp.net core2.1
My model
public class User : Iuser
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int? Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
[NotMapped]
public string Password { get; set; }
[NotMapped]
public string ConfirmPassword { get; set; }
public string Hash { get; set; }
public string Salt { get; set; }
public DateTime? CreatedOn { get; set; }
public User(int? id = null, string firstname = null, string lastname = null, string email = null, string password = null, string confirmpassword = null)
{
this.Id = id;
this.FirstName = firstname;
this.LastName = lastname;
this.Email = email;
this.Password = password;
this.ConfirmPassword = confirmpassword;
}
public User(Iuser obj)
{
this.Id = obj.Id;
this.FirstName = obj.FirstName;
this.LastName = obj.LastName;
this.Email = obj.Email;
this.Password = obj.Password;
this.ConfirmPassword = obj.ConfirmPassword;
}
my Context`
public class UserContext : BaseDbContext
{
public DbSet<User> Users { get; set; }
public UserContext()
{
}
public UserContext(DbContextOptions<UserContext> options):base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(CL.Config.DbConfig.ConnectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(u =>
{
u.HasKey(e => e.Id);
u.Property(e => e.FirstName);
u.Property(e => e.LastName);
u.Property(e => e.Email);
u.Property(e => e.Password);
u.Property(e => e.ConfirmPassword);
u.Property(e => e.Salt);
u.Property(b => b.Hash);
});
}
public void AddUser(User entity)
{
using (UserContext context = new UserContext())
{
entity.CreatedOn = DateTime.Now;
nfigFile(entity.Password, "MD5");
context.Users.Add(entity);
context.SaveChanges();
}
}
}
(BaseDbContext inherits from DbContext)