Multiple Nested Tables - ServiceStack Ormlite

拥有回忆 提交于 2019-12-12 14:24:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!