10

データベース(3.5 SP1)に対して機能する次のLINQクエリを取得しようとしています。

var labelIds = new List<int> { 1, 2 };
var customersAggregatedTransactionsByType =
    (from transactions in context.TransactionSet
    from customers in context.CustomerSet
        .Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds))
    from accounts in context.AccountSet
    where customers == accounts.Customer
        && accounts.Id == transactions.Account.Id
        && transactions.DateTime >= fromDate && transactions.DateTime < toDate
    group transactions.Amount
    by new
    {
        UserAccountId = transactions.Account.Id,
        TransactionTypeId = transactions.TransactionTypeId,
        BaseAssetId = accounts.BaseAssetId
    } into customerTransactions
    select customerTransactions).ToList();

追加するWhere(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds))と、次の例外が発生します。

System.InvalidOperationException:内部.NETFrameworkデータプロバイダーエラー1025。

私がすべてを削除した場合はWhere(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds))良いです。

どんな助けでもありがたいです。

ありがとう、ニール。

4

1 に答える 1

11

試す:

        var labelIds = new List<int> { 1, 2 };
        var exp = LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds);
        var customersAggregatedTransactionsByType =
             (from transactions in context.TransactionSet
              from customers in context.CustomerSet.Where(exp)
              from accounts in context.AccountSet
              where customers == accounts.Customer
                 && accounts.Id == transactions.Account.Id
                 && transactions.DateTime >= fromDate && transactions.DateTime < toDate
              group transactions.Amount
              by new
              {
                  UserAccountId = transactions.Account.Id,
                  TransactionTypeId = transactions.TransactionTypeId,
                  BaseAssetId = accounts.BaseAssetId
              } into customerTransactions
              select customerTransactions).ToList();

それ自体への呼び出しではなく、クエリの結果が必要です。LinqTools.BuildContainsExpression

于 2010-10-04T14:27:36.763 に答える