I don't think you can convert the string to LINQ anyway, but I could be wrong. Assuming you can, someone accessing your web-service could potentially add malicious LINQ code (like the SQL dependancy injection I mentioned in my last post) which would breach the security of your system. In effect you'd be giving anyone with a enough technical knowledge the ability to execute code they'd written on your server, which is very dangerous. If the LINQ query is going to change between pages this suggests that either you should have multiple validation methods on your service per page/ set of field names. If this would lead to too many methods you could pass up a page identifier and select a "where" predicate, one possible solution might look like:
// Syntax1
bool DefaultPredicate(YourClassType value)
{
return value.CompCd == 2; //Or whatever.
}
bool predicatePage1(YourClassType value)
{
return value.CompCd == 2; //Or whatever.
}
//Syntax2
Func<YourClassType, bool> predicatePage2 = (x) => x.CompID == 2 && x.CompCd == 1 ;
private Func<YourClassType, bool> GetPredicate(int pageNumber)
{
if(pageNumber == 1)
return predicatePage1;
if (pageNumber == 2)
return predicatePage2;
return DefaultPredicate;
}
//Page number could be string page code etc. there is probably a way to get this without
//needing to pass it up form the HTTP Context if you want to avoid having to remember to
//send this up each time.
public bool CheckDesc(string departmemtName, int pageNumber)
{
...
Func<YourClassType, bool> predicate = GetPredicate(pageNumber);
var val = DC.DEPTS.Where(predicate).Select(x => x.DeptNM);
...
}
Having said that, I suspect there will be a better solution than the above as the need to make such verification on a per-page basis implies that there is an underlying design flaw that could be refactored out. Hope this helps!!!