Entity Framework BuildContainsExpression Causes Internal .NET Framework Data Provider error 1025

天大地大妈咪最大 提交于 2019-12-23 07:38:11

问题


I'm trying to get the following LINQ query to work against the database (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();

Once I add Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds)) I get the following exception:

System.InvalidOperationException: Internal .NET Framework Data Provider error 1025.

If I remove Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds)) all's good.

Any help will be appreciated.

Thanks, Nir.


回答1:


Try:

        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();

You want the result in the query, not the call to LinqTools.BuildContainsExpression itself.



来源:https://stackoverflow.com/questions/3850649/entity-framework-buildcontainsexpression-causes-internal-net-framework-data-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!