2016-05-03 5 views
0
List<System.Linq.Expressions.Expression<Func<MyType, bool>>> lstPredicates = new List<System.Linq.Expressions.Expression<Func<MyType, bool>>>(); 

foreach (MyType myAccount in lstMyType) 
{ 
    System.Linq.Expressions.Expression<Func<MyType, bool>> predicate = 
     t => t.Account == myAccount.Account && t.Branch == myAccount.Branch; 
    lstPredicates.Add(predicate); 
} 

lstTransactions = Context.MyTrans 
    .Where(lstPredicates) 
    .ToList(); 

Ich versuche, das Nachschlagen in MyTrans Tabelle nur einmal zu laufen, so dass ich bin der Aufbau eine Liste von Prädikaten auf. Ich möchte Transaktionen in einer Liste abrufen, in der Konto- und Zweigkombinationen in Transaktionen vorhanden sind.Liste der Prädikate in Entity Framework Where-Klausel

d Ich versuche, ein Prädikat wie

predicate = t => 
    (t.Account == 123 && t.Branch == London) 
    || (t.Account == 433 && t.Branch == Manchester) 
    ||... 
+0

ich nur in Betracht ziehen würden einen einzigen expresion und .Contains() verwendet wird. Beispiel Wo (x => yourListOfIDs.Contains (x.Account) –

Antwort

0

zu produzieren Sie Linqkit Bibliothek nutzen könnten. Mit PredicateBuilder Sie können im Anschluss an die tun:

var predicate = PredicateBuilder.False<MyType>(); 

foreach (MyType myAccount in lstMyType) 
{ 
    predicate = predicate.Or (
     t => t.Account == myAccount.Account && t.Branch == myAccount.Branch); 
} 

var query= Context.MyTrans.AsExpandable().Where(predicate); 
Verwandte Themen