多个嵌套表 - ServiceStack Ormlite [英] Multiple Nested Tables - ServiceStack Ormlite

查看:52
本文介绍了多个嵌套表 - ServiceStack Ormlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组嵌套表

例如.客户 -> 客户订单 -> 订单详情....

eg. Customer -> Customer Order -> Order Details….

我与服务堆栈和 ormlite 一起使用...我需要能够传递一个客户 ID,然后返回一个 json 提要,其中包含嵌套在客户对象中的客户订单和嵌套在每个客户订单对象中的订单详细信息...努力实现这一目标.

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;

并且也看到了@mythz的这篇文章ServiceStack OrmLite 如何实现外键/相关属性的自动设置? 我安装了哪个(服务堆栈的新版本...... 4.0)......但是都没有解决加载超过第二级嵌套(即无法加载订单详细信息).

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).

非常感谢任何帮助.

推荐答案

在 ormlite 4 中发现最简单的方法就是遍历每个客户订单

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);
            }    

这是最有效的方法吗?

这篇关于多个嵌套表 - ServiceStack Ormlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆