0

We would like to perform something like this

string strCondition = "FirstName=='abc'" from p in People.Where(strCondition) select p

In our architecture we are usign both Linq-Sql as well Linq-Entity. So please give some thoughts wehter it is possible or not and is there any way to perform this?

tereško
  • 58,060
  • 25
  • 98
  • 150
ArpanDesai
  • 87
  • 3
  • 11
  • How do you know how to select that string in the first place? What other parameters are possible. There's so much context missing from your question it's impossible to know where to begin, please edit it. – Garry Shutler Dec 24 '10 at 12:37
  • http://stackoverflow.com/questions/4510568/using-a-list-as-a-condition-for-linq-to-sql-query/4510597#4510597 – Jahan Zinedine Dec 24 '10 at 12:40

2 Answers2

1

Dynamic LINQ should work for you.

alt text

decyclone
  • 30,394
  • 6
  • 63
  • 80
1

yeah it is possible; Func < EntityName,Bool> testObj = o=> o.name == "Abc";

EntityName will be the entityname on which u r suppose to perform search

and use it in the linq query as like

Dc.EntityName.where(testObj);

where Dc is the object of dataContext

slash shogdhe
  • 3,943
  • 6
  • 27
  • 46
  • So do you mean that for each property we need to define one testObj delegate. And then we can pass it to the Where condition after checking null. M i right? – ArpanDesai Dec 27 '10 at 06:37
  • yeah,this is the best and only way to use...the only prob is u can not use this in wcf operationcontext as testObj is not serialized – slash shogdhe Dec 30 '10 at 05:45