【发布时间】:2010-11-20 02:57:51
【问题描述】:
我习惯于使用LoadWith 语法加载一些子结果(对于父结果)。效果很好。有没有办法可以将这些 LoadWith 结果限制为最近的 5 个或其他什么?
我有一些带有一些内联 cmets 的伪代码来帮助解释我正在尝试做什么......
例如。
IList<Parent> results;
using (DataBaseContext db = new MyDb())
{
var dlo = new DataLoadOptions();
dlo.LoadWith<Parent>(x => x.Child1); // We only want the most recent 10.
dlo.LoadWith<Parent>(x => x.Child2); // All of these...
dlo.LoadWith<Parent>(x => x.Child3); // Only the most recent 1.
db.LoadOptions = dlo;
results = (from p in Parent
orderby p.Id descending
select p).Take(5).ToList();
}
干杯:)
【问题讨论】:
-
这个问题可能有可以回答这个问题的答案:stackoverflow.com/questions/4221/…
标签: .net linq-to-sql