0

如何从复杂的 LINQ 查询中获取 10 条记录?我试图 put .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
    };
4

1 回答 1

2

只是写

.Skip(X).Take(10)

会给你类型的输出,IEnumerable<T>但你的是List<T>类型。

所以你应该使用

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

在你的情况下。

于 2012-10-11T08:56:43.650 回答