How dynamic can I make my LINQ To SQL Statements?

Posted by mcass20 on Stack Overflow See other posts from Stack Overflow or by mcass20
Published on 2010-05-14T15:05:19Z Indexed on 2010/05/15 6:54 UTC
Read the original article Hit count: 418

Filed under:
|
|
|
|

I have the need to construct a LINQ To SQL statement at runtime based on input from a user and I can't seem to figure out how to dynamically build the WHERE clause.

I have no problem with the following:

string Filters = "<value>FOO</value>";
Where("FormattedMessage.Contains(@0)",Filters)

But what I really need is to make the entire WHERE clause dynamic. This way I can add multiple conditions at runtime like this (rough idea):

 foreach (Filter filter in filterlist)
            {
                whereclause = whereclause + "&& formattedmessage.contains(filter)";
            }

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#