Dynamic Linq searching multiple columns of multiple types including nullable types

c# dynamic-linq expression-trees linq

Question

I need select my columns dynamically and I do not know the types of the columns ahead of time. I've got a string and I want to search all the columns if they contain that string, converting non-string into string for the comparison.

string format = "Convert.ToString({0}).Contains(@0)";
Model.Where(String.Format(format, columnName), searchString);

It breaks on nullable types, but that should be okay. I can use HasValue and Value and then convert to string. To do that I need to check that the type is Nullable<> with typeof. So I wrote a big nasty string to pass to dynamic linq, and it broke on typeof I've tried to write an expression tree but I'm not getting anywhere. Is there any way to do what I want?

1
2
7/27/2012 7:22:52 PM

Popular Answer

Take a look at this blog post.

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Its about how to operate with DLINQ, it can help

1
11/20/2012 2:04:36 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow