Reputation: 3
I'm building an application in .NET7 with the ardalis/clean-architecture template. I spent yesterday modeling my models, and now I'm trying to migrate so that I can seed data and test some functionalities but I keep getting the error
No suitable constructor was found for entity type 'Agency'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'team' in 'Agency(string name, string email, string phoneNumber, CompanySettings billingInfo, TaxInformation taxInformation, AgencyTeam team)'
Cannot bind 'shippingInfo', 'team' in 'Agency(string name, string email, string phoneNumber, CompanySettings billingInfo, CompanySettings shippingInfo, TaxInformation taxInformation, AgencyTeam team)'
My models look like this:
Agency.cs
public class Agency : Company, IAggregateRoot
{
public AgencyTeam Team { get; private set; }
public Agency(
string name,
string email,
string phoneNumber,
CompanySettings billingInfo,
TaxInformation taxInformation,
AgencyTeam team
)
: base(name, email, phoneNumber, billingInfo, taxInformation)
{
Team = Guard.Against.Null(team, nameof(team));
}
public Agency(
string name,
string email,
string phoneNumber,
CompanySettings billingInfo,
CompanySettings shippingInfo,
TaxInformation taxInformation,
AgencyTeam team
)
: base(name, email, phoneNumber, billingInfo, shippingInfo, taxInformation)
{
Team = Guard.Against.Null(team, nameof(team));
}
}
Agency inherits from Company.cs:
public class Company : EntityBase, IAggregateRoot
{
public string Name { get; private set; }
public string Email { get; private set; }
public string PhoneNumber { get; private set; }
public CompanySettings BillingInfo { get; private set; }
public CompanySettings ShippingInfo { get; private set; }
public TaxInformation TaxInformation { get; private set; }
public DateTime CreatedAt { get; private set; }
public Company(string name, string email, string phoneNumber, CompanySettings billingInfo, CompanySettings shippingInfo, TaxInformation taxInformation)
{
Name = Guard.Against.NullOrEmpty(name, nameof(name));
Email = Guard.Against.NullOrEmpty(email, nameof(email));
PhoneNumber = Guard.Against.NullOrEmpty(phoneNumber, nameof(phoneNumber));
BillingInfo = Guard.Against.Null(billingInfo, nameof(billingInfo));
ShippingInfo = Guard.Against.Null(shippingInfo, nameof(shippingInfo));
TaxInformation = Guard.Against.Null(taxInformation, nameof(taxInformation));
CreatedAt = DateTime.Now;
}
public Company(string name, string email, string phoneNumber, CompanySettings billingInfo, TaxInformation taxInformation)
{
Name = Guard.Against.NullOrEmpty(name, nameof(name));
Email = Guard.Against.NullOrEmpty(email, nameof(email));
PhoneNumber = Guard.Against.NullOrEmpty(phoneNumber, nameof(phoneNumber));
BillingInfo = Guard.Against.Null(billingInfo, nameof(billingInfo));
ShippingInfo = BillingInfo;
TaxInformation = Guard.Against.Null(taxInformation, nameof(taxInformation));
CreatedAt = DateTime.Now;
}
}
AgencyTeam.cs
public class AgencyTeam : EntityBase
{
public AgencyTeam() { }
}
AgencyUser.cs
public class AgencyUser : ApplicationUser
{
public AgencyTeam Team { get; private set; }
private List<Contact> _assignedContacts = new List<Contact>();
[PersonalData]
public IEnumerable<Contact> AssignedContacts => _assignedContacts.AsReadOnly();
private List<ProjectAggregate.Task> _assignedTasks = new List<ProjectAggregate.Task>();
[PersonalData]
public IEnumerable<ProjectAggregate.Task> AssignedTasks => _assignedTasks.AsReadOnly();
public AgencyUser(string firstName, string lastName, string jobTitle, AgencyTeam team)
: base(firstName, lastName, jobTitle)
{
Team = Guard.Against.Null(team, nameof(team));
}
}
CompanySettings.cs
public class CompanySettings : EntityBase
{
public string Email { get; private set; }
public Address Address { get; private set; }
public CompanySettings(string email, Address address)
{
Email = Guard.Against.NullOrEmpty(email, nameof(email));
Address = Guard.Against.Null(address, nameof(address));
}
}
I spent some time looking around for answers and found this topic: No suitable constructor found for entity type string and I also looked at some other similar topics, but I keep getting the error but managed to fix it for some of my models, except for this one.
Really hoping someone can help me out :)
Upvotes: 0
Views: 93