1

I am sure this is something really simple, but I am going bonkers trying to figure out why.

I have the following code:

string condition = string.Format("{0}.Contains({1})", column, value);

var query = DataContext.MyTable.Where(condition);

The strange thing that I am getting is an error saying:

Argument cannot convert from string to 'System.Linq.Expressions.Expression<System.Func<Context.MyTable, bool>>'

I thought that you could pass in a string to the where clause without a problem such as indicated in this post:

Dynamic WHERE clause in LINQ

Any thoughts on what I am missing? Perhaps an invalid namespace (I have System.Linq)?

2 Answers 2

3

You need to:

  1. Download dynamic query with the C# samples.
  2. Reference it in your project.
  3. Add using System.Linq.Dynamic
  4. Follow the format specified in the documentation for that library.
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I am giving you accepted answer only because you answered first and I found the information before the other person posted and I did not see his post until after I got it to work. This worked like a charm. Thanks.
3

That answer has a link to a library that you need to download.

1 Comment

Thanks I did not see that in there before. +1 for the info though. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.