2
I am creating a user register in C#, but when including the Domain layer and I will create the Migration is happening the error below. I haven’t been able to identify what happens.
"No suitable constructor found for Entity type 'User'. The following Parameters could not be bound to properties of the Entity: 'cellphone', 'address'."
namespace AgendaWeb.Domain.Users
{
public class User
{
public int Id { get; private set; }
public string UserName { get; private set; }
public string FullName { get; private set; }
public string Cpf { get; private set; }
public string Email { get; private set; }
public string Phone { get; private set; }
public string Cellphone { get; private set; }
public string PhotoUrl { get; private set; }
public string Password { get; private set; }
public DateTime RegistrationDate { get; private set; }
public DateTime? DateOfBirth { get; private set; }
public string ProfileType { get; private set; }
public Address Address { get; private set; }
public User(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address )
{
ValidateValues(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
SetProperties(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
}
public void Update(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
ValidateValues(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
SetProperties(userName, fullName, cpf, email, phone, cellPhone, photoUrl, password, registrationDate, dateOfBirth, profileType, address);
}
private void SetProperties(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
UserName = userName;
FullName = fullName;
Cpf = cpf;
Email = email;
Phone = phone;
Cellphone = cellPhone;
PhotoUrl = photoUrl;
Password = password;
RegistrationDate = registrationDate;
DateOfBirth = dateOfBirth;
ProfileType = profileType;
Address = address;
}
private static void ValidateValues(string userName, string fullName, string cpf, string email, string phone, string cellPhone, string photoUrl, string password, DateTime registrationDate, DateTime? dateOfBirth, string profileType, Address address)
{
DomainException.When(string.IsNullOrEmpty(userName), "O campo nome é obrigatório!");
}
}
}
as Gustavo has already answered, you need to have a constructor without parameters for EF to create an instance, you can simply add
public User(){}
to his class– Rovann Linhalis