本文介绍了实体框架BuildContainsExpression导致内部.NET Framework数据提供程序错误1025的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获得以下LINQ查询来处理数据库(3.5 SP1):

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

添加之后(LinqTools.BuildContainsExpression< Billing.Customer,int> (u => uLabelId,labelIds))我得到以下异常:

System.InvalidOperationException:Internal .NET框架数据提供者错误1025。

如果我删除其中(LinqTools.BuildContainsExpression< Billing.Customer,int>(u => ; u.LabelId,labelIds)) all's good。

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

任何帮助将不胜感激。

谢谢,Nir。

推荐答案

尝试:

        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 本身。

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

这篇关于实体框架BuildContainsExpression导致内部.NET Framework数据提供程序错误1025的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:32