Entity framework 实体框架BuildContainesPression导致内部.NET Framework数据提供程序错误1025
我正在尝试使以下LINQ查询对数据库(3.5 SP1)起作用:Entity framework 实体框架BuildContainesPression导致内部.NET Framework数据提供程序错误1025,entity-framework,internal,Entity Framework,Internal,我正在尝试使以下LINQ查询对数据库(3.5 SP1)起作用: var labelIds=新列表{1,2}; var CustomerAggregatedTransactionsByType= (来自context.TransactionSet中的事务) 来自context.CustomerSet中的客户 .Where(LinqTools.buildContainesPression(u=>u.LabelId,LabelId)) 来自context.AccountSet中的帐户 其中custom
var labelIds=新列表{1,2};
var CustomerAggregatedTransactionsByType=
(来自context.TransactionSet中的事务)
来自context.CustomerSet中的客户
.Where(LinqTools.buildContainesPression(u=>u.LabelId,LabelId))
来自context.AccountSet中的帐户
其中customers==accounts.Customer
&&accounts.Id==transactions.Account.Id
&&transactions.DateTime>=fromDate&&transactions.DateTime
一旦我添加了Where(LinqTools.buildContainesPression(u=>u.LabelId,LabelId))
我会得到以下异常:
System.InvalidOperationException:内部.NET Framework数据提供程序错误1025。
如果我删除Where(LinqTools.buildcontainsepression(u=>u.LabelId,LabelId))
一切正常
任何帮助都将不胜感激
谢谢,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();
var labelIds=新列表{1,2};
var exp=LinqTools.buildContainesPression(u=>u.LabelId,LabelId);
var CustomerAggregatedTransactionsByType=
(来自context.TransactionSet中的事务)
来自context.CustomerSet.Where(exp)中的客户
来自context.AccountSet中的帐户
其中customers==accounts.Customer
&&accounts.Id==transactions.Account.Id
&&transactions.DateTime>=fromDate&&transactions.DateTime
您希望查询结果,而不是调用
LinqTools.buildContainesPression
本身。哦,你这个天才!我在一小时前打开了一张悬赏卡,后来才找到你的答案。请去那边给自己弄一份赏金。这听起来很明显,但你是对的,表达式必须在查询本身之外构建。
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();