问题
I have a set of nested tables
eg. Customer -> Customer Order -> Order Details….
which Im using with service stack and ormlite... I need to be able to be able to pass in a customerid and then return a json feed with customer orders nested within the customer object and order details nested within each customer order object... struggling to acheive this.
Ive seen a plural site vid that handles down to the second layer and works well eg.
var customer = Db.GetByIDorDefault<Customer>(CustomerId);
var customerorder = Db.Where<CustomerOrder>(a => a.CustomerId == CustomerId);
customer.CustomerOrder.AddRange(customerorder);
return customer;
and also have seen this post by @mythz ServiceStack OrmLite How can I achieve automatic setting of foreign key/related properties? which ive installed (new version of service stack... 4.0)... however neither solve loading past the 2nd level of nesting (ie couldn’t load Order Details).
Any help is much appreciated.
回答1:
Found the easiest way to do it in ormlite 4 was just to iterate through each customer order
// Iterate through Orders
foreach (var t in customer.CustomerOrder)
{
Db.LoadReferences(t);
}
is that the most efficient way to do it?
来源:https://stackoverflow.com/questions/20076439/multiple-nested-tables-servicestack-ormlite