Dynamic Linq searching multiple columns of multiple types including nullable types

c# dynamic-linq expression-trees linq

Question

I must dynamically choose my columns since I am unsure of their kinds beforehand. I have a string, and I want to transform a non-string into a string so that I can compare if it appears in any of the columns.

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

Nullable types cause it to fail, but that should not be a problem. I can convert to a string using HasValue and Value. I must use typeof to verify that the type is Nullable in order to do that. I created a large, unpleasant string to send to dynamic linq, and it malfunctioned ontypeof Even though I've attempted to create an expression tree, I'm having no luck. Is it possible to accomplish my goals?

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

Popular Answer

Check out this blog entry.

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

It explains how to use DLINQ and may be helpful.

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