Skip to content

Instantly share code, notes, and snippets.

@plioi plioi/ComplexTypes.cs
Last active Feb 9, 2016

Embed
What would you like to do?
public abstract class Entity
{
public Guid Id { get; set; }
}
public class Customer : Entity
{
public Customer()
{
Orders = new List<Order>();
Address = new Address();
}
public string Name { get; set; }
public Address Address { get; set; }
public string Email { get; set; }
public virtual ICollection<Order> Orders { get; private set; }
public Order AddOrder(Order order)
{
Orders.Add(order);
order.Customer = this;
return order;
}
}
public class Order : Entity
{
public Order()
{
OrderDetails = new List<OrderDetail>();
BillingAddress = new Address();
}
public virtual Customer Customer { get; set; }
public DateTime PurchaseTime { get; set; }
public Address BillingAddress { get; set; }
public virtual ICollection<OrderDetail> OrderDetails { get; }
public OrderDetail AddDetail(OrderDetail detail)
{
OrderDetails.Add(detail);
detail.Order = this;
return detail;
}
}
public class OrderDetail : Entity
{
public virtual Order Order { get; set; }
public string Description { get; set; }
public decimal UnitPrice { get; set; }
public int Quantity { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
}
public class CustomerConfig : EntityTypeConfiguration<Customer>
{
public CustomerConfig()
{
Property(p => p.Address.Street).HasColumnName("Street");
Property(p => p.Address.City).HasColumnName("City");
Property(p => p.Address.State).HasColumnName("State");
Property(p => p.Address.PostalCode).HasColumnName("PostalCode");
}
}
public class OrderConfig : EntityTypeConfiguration<Order>
{
public OrderConfig()
{
Property(p => p.BillingAddress.Street).HasColumnName("BillingStreet");
Property(p => p.BillingAddress.City).HasColumnName("BillingCity");
Property(p => p.BillingAddress.State).HasColumnName("BillingState");
Property(p => p.BillingAddress.PostalCode).HasColumnName("BillingPostalCode");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.