sql - How to do this dynamic where clause in EF -


Some advice about how to deal with the following selected queries with EF

* Note, I Need help with SELECT only via e-mail. Insert a table table or stuff for a sample of my table structure. Create sample SampleTable value (1, 'GoodData'), (2, 'BetterData'), (2, 'whatever' Select from where SampleTable (* 10, 'GoodData') * Fu = 2 and Bar = 'BetterData') or (Fu = 1 and Bar = 'GoodData') --There these lines 'or' lines leave the table SampleTable

Here are a couple of methods of extension:

  Public Static Class PredicateBuilder {Public Static Expression & lt; Funk & Lt; T, boolean & gt; & Gt; True & lt; T & gt; () {Return F = & gt; truth; } Public steady expression & lt; Func & lt; T, bool & gt; & Gt; Wrong & lt; T & gt; () {Return f = & gt; false; } Public steady expression & lt; Func & lt; T, bool & gt; & Gt; Or & lt; T & gt; (This expression was & lt; t, bool & gt; expr1 of the function & lt; t, bool & gt; expr2 of the function & quot; function of {var invokedExpr = Expression. Invoke (expr2, expr1.Parameters.Cast & lt; expression & gt; ()); Return expression. Lambda & lt; Funk & lt; T, bool & gt; & Gt; (Expression. Orese (XPR 1. Body, Inqux XPR), XPR 1. Parameter); } Public steady expression & lt; Func & lt; T, bool & gt; & Gt; And & lt; T & gt; (This expression was & lt; t, bool & gt; expr1 of the function & lt; t, bool & gt; expr2 of the function & quot; function of {var invokedExpr = Expression. Invoke (expr2, expr1.Parameters.Cast & lt; expression & gt; ()); Return expression. Lambda & lt; Funk & lt; T, bool & gt; & Gt; (Expression and also (expr1.Body, invokedExpr), expr1.Parameters); }}   

Then use it for your dynamic query needs:

  expression & lt; Funk & lt; SampleTableObject, bool & gt; & Gt; Predicate = PredicateBuilder.True & lt; SampleTableObject & gt; (); Forresh (list item in situations) {predicate = predicate.or (x => x.Foo == item.Foo & X. Bar == item bar); } Var data = EFContext.SampleTableObjects.Where (predicate);    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -