Sorry if this is a simple thing, but I’m just learn EF and can’t seem to find my answer (or maybe it’s just understand what I’m finding).
I have three existing database tables as follows:
Order:
int OrderNo (Primary Key generated by program)
...
OrderDetails:
int OrderNo (Foreign key from Order=>OrderNo; but part of primary key for OrderDetails)
int DetailNo (Part of primary key; generated by program)
...
OrderResults:
int OrderNo (Key from Detail=>OrderNo; but part of primary key for OrderResults)
int DetailNo (Key from Detail=>DetailNo; but part of primary key fro OrderResult)
int ResultNo (Part of primary key; generated by program)
...
My Entities are defined as:
public Class Order
{
public int OrderNo { get; set; }
publice virtual ICollection<Detail> Details { get; set; }
}
public Class Detail
{
public int OrderNo { get; set; }
public int DetailNo { get; set; }
public virtual Order Order { get; set; }
public virtual ICollection<Result> Results { get; set; }
}
public Class Result
{
public int OrderNo { get; set; }
public int DetailNo { get; set; }
public int ResultNo { get; set; }
public virtual Detail Detail { get; set; }
}
So how would you define these key and associations using the fluent API? Currently I’m getting the OrderDetails linked to the Order correctly, but not getting the correct OrderResults.
You can try something like this:
Fluent API is quite verbose in this example. You can all the mappings also define with data annotations.