实体框架BuildContainsExpression导致内部.NET Framework数据提供程序错误1025

nir*_*rpi 9 entity-framework internal

我正在尝试使用以下LINQ查询来对数据库(3.5 SP1)起作用:

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();
Run Code Online (Sandbox Code Playgroud)

一旦我添加,Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds))我得到以下异常:

System.InvalidOperationException:内部.NET Framework数据提供程序错误1025.

如果我删除Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds))所有的好.

任何帮助将不胜感激.

谢谢,Nir.

Cra*_*ntz 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();
Run Code Online (Sandbox Code Playgroud)

您希望查询中的结果,而不是对LinqTools.BuildContainsExpression自身的调用.

  • 哦,天才!一小时前,我在[类似问题](http://stackoverflow.com/q/11990158/7850)上开了一笔赏金,后来才找到了答案.请去那里获得赏金. (2认同)