2010-10-03 2 views
9

Ich versuche, die folgende LINQ-Abfrage für die Datenbank zur Arbeit zu kommen (3.5 SP1):Entity Framework BuildContainsExpression Ursachen Interne .NET Framework Data Provider Fehler 1025

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

Sobald ich hinzufügen Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds)) ich folgendes erhalten Ausnahme:

System.InvalidOperationException: Interner .NET Framework Data Provider Fehler 1025.

Wenn ich Where(LinqTools.BuildContainsExpression<Billing.Customer, int>(u => u.LabelId, labelIds)) entfernen alles ist gut.

Jede Hilfe wird geschätzt.

Danke, Nir.

Antwort

11

Versuchen:

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

Sie wollen das Ergebnis in der Abfrage, den Anruf nicht zu LinqTools.BuildContainsExpression selbst.

+0

Das ist es! Danke vielmals! – nirpi

+2

Oh, du Genie! Ich habe vor einer Stunde ein Kopfgeld auf eine [ähnliche Frage] (http://stackoverflow.com/q/11990158/7850) eröffnet und erst später deine Antwort gefunden. Bitte geh und hol dir eine Prämie drüben. –

+0

Es klingt offensichtlich, aber Sie haben Recht, der Ausdruck muss außerhalb der Abfrage selbst erstellt werden. –

Verwandte Themen