从复杂的LINQ查询中获取X记录

时间:2012-10-09 16:20:43

标签: linq c#-4.0 linq-to-sql linq-to-entities

如何从复杂的LINQ查询中获取10条记录? 我试图放.Skip(X).Take(10),但它不起作用,取决于我试图采取的地方10它返回完整的对象集或什么也没有。

在查询结束时设置.Skip(X).Take(10)并不是因为性能低下而无法找到的。

这是我的疑问:

List<ReportReturn> report =  
    from var1 in context.Table1
    join var2 in context.Table2
        on var1.AccountID equals var2.AccountID
    join var3 in context.Table3
        on var1.AccountID equals var3.AccountID into all
    where 
        var1.SubAccountID == intSubAccountID && 
        // ...... and more conditions

    let actual = var1.Total.GetValueOrDefault(0)
    let Unique = var2.CountUnique 
    let Total = var2.Count

    // ........ and more helper values

    orderby var1.Date descending

    from final in all.DefaultIfEmpty()
    select new ReportReturn {
        // ........................some property assigments
    };

1 个答案:

答案 0 :(得分:2)

只写

.Skip(X).Take(10)

会以IEnumerable<T>类型为您提供输出,但您的输出为List<T>类型。

所以你应该使用

.Skip(X).Take(10).ToList()

在你的情况下。