Skip to content

Instantly share code, notes, and snippets.

@plioi
Last active February 9, 2016 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plioi/17fd74b2549faa344f65 to your computer and use it in GitHub Desktop.
Save plioi/17fd74b2549faa344f65 to your computer and use it in GitHub Desktop.
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