I'm learning C# at the moment with .NET Core and EF Core for working with database.
Now I'm at the point where I got stuck configuring my entities.
I have written the following classes:
public class Customer
{
#region Properties
public Guid CustomerID { get; set; }
...
public Address Address { get; set; }
#endregion
public Customer()
{
Address = new Address();
}
}
public class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
public void Configure(EntityTypeBuilder<Customer> builder)
{
//Primary Key
builder.HasKey(c => c.CustomerID);
//Complex Types
builder.OwnsOne<Address>("Address");
}
}
public class Employee
{
#region Properties
public Guid EmployeeID { get; set; }
...
public Address Address { get; set; }
#endregion
public Employee()
{
Address = new Address();
}
}
public class EmployeeConfiguration : IEntityTypeConfiguration<Employee>
{
public void Configure(EntityTypeBuilder<Employee> builder)
{
//Primary Key
builder.HasKey(c => c.EmployeeID);
//Complex Types
builder.OwnsOne<Address>("Address");
}
}
public class Address
{
public string Street { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
public State State { get; set; }
public Country Country { get; set; }
}
I need to configure Address class with Fluent API that Address.Street is for Customer and Employee MaxLength = 50?
Is it possible to configure it for both at the same time? Or do I need to configure it for each entity?
Thanks for your help!