I have a quick question about setting up mappings between [Order Details], [Products]and [Orders]in a Northwind database.
[Order Details] does not have a primary key and looks as follows
[Order Details]
OrderId (int)
ProductId (int)
...
So my question is: how do I (and can I) configure my class OrderDetailsto work as follows?
public class OrderDetails
{
public virtual Order Order { get; set; }
public virtual Product Product { get; set; }
public Decimal UnitPrice { get; set; }
public int Quantity { get; set; }
public Decimal Discount { get; set; }
}
My data context is as follows
public class NorthwindDb : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetails> OrderDetails { get; set; }
public DbSet<Customer> Customers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new OrderDetailsConfiguration());
}
public static void InitializeBecauseOfThatWeirdMetaDataThingThatIDontUnderstandYet()
{
Database.SetInitializer<NorthwindDb>(null);
}
}
And Mine OrderDetailsConfiguration(empty because I don't know what I'm doing)
public class OrderDetailsConfiguration : EntityConfiguration<OrderDetails>
{
public OrderDetailsConfiguration()
{
}
}
Any tips or ideas would be great.
source
share