Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7552909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:54:19+00:00 2026-05-30T10:54:19+00:00

UPDATE : Groo’s answer was marked correct as it would be a good alternative.

  • 0

UPDATE: Groo’s answer was marked correct as it would be a good alternative. I decided to stick with the select/switch statements to avoid the performance issues of using reflection. As far as I can tell there is no way to do what I want without using Dynamic LINQ (and reflection) or a decompiler (to manually code each LINQ statement, which I am already doing by hand). Note: to make this update DropDownList16 through DropDownList20 were removed (needed the characters).


Is there a way to abstract the building of a dynamic Linq to SQL query?

I am trying to build a Linq to SQL query with a dynamic where clause, based on user supplied filters. The user needs to be able to filter strings, integers, and dates using advanced options (equal, not equal, contains, starts with, etc). The user needs to be able to use these filters with as many or few columns as desired.

My current switch for one column:

VB

Select Case type
    Case StringFilterTypes.Any  ''//Do nothing (same as else)
    Case StringFilterTypes.Contains
        query = From view In query Where view.Name.Contains(userValue) Select view
    Case StringFilterTypes.Exactly
        query = From view In query Where view.Name = userValue Select view
    Case StringFilterTypes.StartsWith
        query = From view In query Where view.Name.StartsWith(userValue) Select view
    Case StringFilterTypes.EndsWith
        query = From view In query Where view.Name.EndsWith(userValue) Select view
    Case Else                   ''//Do nothing (same as Any).
End Select

C#

switch (type) {
    case StringFilterTypes.Any: //Do nothing (same as else)
        break;
    case StringFilterTypes.Contains:
        query = from view in querywhere view.Name.Contains(userValue)view;
        break;
    case StringFilterTypes.Exactly:
        query = from view in querywhere view.Name == userValueview;
        break;
    case StringFilterTypes.StartsWith:
        query = from view in querywhere view.Name.StartsWith(userValue)view;
        break;
    case StringFilterTypes.EndsWith:
        query = from view in querywhere view.Name.EndsWith(userValue)view;
        break;
    default:                    //Do nothing (same as Any).
        break;
}

I will need to use this select/switch with all the string columns and a similar switch with all the integer and datetime columns. As a result, I want to make these select/switch statments into a function where the type, view.Name, and userValue are supplied variables. I can pass type and userValue since they are local variables, but how can I pass view.Name into the function?

I have looked into extensions, but they seem to require that I pass view, know the column already, and don’t support select/switch statements.
I also looked into adding the where statements as strings but feel this removes the only two reasons for using linq (compiler verified queries, automated escaping of user input to prevent sql injection).
Expression Trees look promising, but I am not sure how to use them and if they are a good idea where performance is an issue.

The best solution would be something like:

VB

Public Function ApplyFilters(query As IQueryable(Of DBName.ViewName)) As IQueryable(Of DBName.ViewName)
    ''//...
    Filter_String (query, Type, View.Name, userValue)
    ''//...
End Function
Public Function Filter_String (query As IQueryable(Of DBName.ViewName), type As StringFilterTypes, column as ???, userValue As String) As IQueryable(Of DBName.ViewName)
    Select Case type
        Case StringFilterTypes.Any  ''//Do nothing (same as else)
        Case StringFilterTypes.Contains
            query = From view In query Where column.Contains(userValue) Select view
        Case StringFilterTypes.Exactly
            query = From view In query Where column = userValue Select view
        Case StringFilterTypes.StartsWith
            query = From view In query Where column.StartsWith(userValue) Select view
        Case StringFilterTypes.EndsWith
            query = From view In query Where column.EndsWith(userValue) Select view
        Case Else                   ''//Do nothing (same as Any).
    End Select

    Return query
End Function

C#

public IQueryable<DBName.ViewName> ApplyFilters(IQueryable<DBName.ViewName> query)
{
    //...
    Filter_String (query, Type, View.Name, userValue);
    //...
}
public IQueryable<DBName.ViewName> Filter_String(IQueryable<DBName.ViewName> query, StringFilterTypes type, ??? column, string userValue)
{
    switch (type) {
        case StringFilterTypes.Any: //Do nothing (same as else)
            break;
        case StringFilterTypes.Contains:
            query = from view in querywhere column.Contains(userValue)view;
            break;
        case StringFilterTypes.Exactly:
            query = from view in querywhere column == userValueview;
            break;
        case StringFilterTypes.StartsWith:
            query = from view in querywhere column.StartsWith(userValue)view;
            break;
        case StringFilterTypes.EndsWith:
            query = from view in querywhere column.EndsWith(userValue)view;
            break;
        default:
            break;                  //Do nothing (same as Any).
    }

    return query;
}

Update 2012/02/27:
For BlueRaja – Danny Pflughoeft I am providing a sample application. Obviously the data connection will have to be supplied by the end user (MS SQL database named “Test” with table named “testTable” and columns named “Column#” where # is all numbers 1-20).

Default.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1.test._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList2" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList3" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList4" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False"  Text ="Contains"    Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList5" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList6" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList7" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList8" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList9" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList10" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList11" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList12" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList13" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False"  Text ="Contains"    Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList14" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False" Text ="Contains"     Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox14" runat="server"></asp:TextBox>
        <br />

        <asp:DropDownList ID="DropDownList15" runat="server">
            <asp:ListItem Selected="True"  Text ="Any"          Value="-1" />
            <asp:ListItem Selected="False"  Text ="Contains"    Value="0" />
            <asp:ListItem Selected="False" Text ="Is exactly"   Value="1" />
            <asp:ListItem Selected="False" Text ="Starts with"  Value="2" />
            <asp:ListItem Selected="False" Text ="Ends with"    Value="3" />
        </asp:DropDownList>
        <asp:TextBox ID="TextBox15" runat="server"></asp:TextBox>
        <br />

        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>

    </div>
    </form>
</body>
</html>

Default.aspx.vb

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        Dim _db As TestDataContext = New TestDataContext(ConfigurationManager.ConnectionStrings("TestDataConn").ConnectionString)

        Dim query As IQueryable(Of testTable) = _
         From view In _db.testTables
         Select view

        Select Case DropDownList1.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column1.Contains(TextBox1.Text) Select view
            Case "1"
                query = From view In query Where view.Column1 = TextBox1.Text Select view
            Case "2"
                query = From view In query Where view.Column1.StartsWith(TextBox1.Text) Select view
            Case "3"
                query = From view In query Where view.Column1.EndsWith(TextBox1.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList2.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column2.Contains(TextBox2.Text) Select view
            Case "1"
                query = From view In query Where view.Column2 = TextBox2.Text Select view
            Case "2"
                query = From view In query Where view.Column2.StartsWith(TextBox2.Text) Select view
            Case "3"
                query = From view In query Where view.Column2.EndsWith(TextBox2.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList3.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column3.Contains(TextBox3.Text) Select view
            Case "1"
                query = From view In query Where view.Column3 = TextBox3.Text Select view
            Case "2"
                query = From view In query Where view.Column3.StartsWith(TextBox3.Text) Select view
            Case "3"
                query = From view In query Where view.Column3.EndsWith(TextBox3.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList4.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column4.Contains(TextBox4.Text) Select view
            Case "1"
                query = From view In query Where view.Column4 = TextBox4.Text Select view
            Case "2"
                query = From view In query Where view.Column4.StartsWith(TextBox4.Text) Select view
            Case "3"
                query = From view In query Where view.Column4.EndsWith(TextBox4.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList5.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column5.Contains(TextBox5.Text) Select view
            Case "1"
                query = From view In query Where view.Column5 = TextBox5.Text Select view
            Case "2"
                query = From view In query Where view.Column5.StartsWith(TextBox5.Text) Select view
            Case "3"
                query = From view In query Where view.Column5.EndsWith(TextBox5.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList6.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column6.Contains(TextBox6.Text) Select view
            Case "1"
                query = From view In query Where view.Column6 = TextBox6.Text Select view
            Case "2"
                query = From view In query Where view.Column6.StartsWith(TextBox6.Text) Select view
            Case "3"
                query = From view In query Where view.Column6.EndsWith(TextBox6.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList7.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column7.Contains(TextBox7.Text) Select view
            Case "1"
                query = From view In query Where view.Column7 = TextBox7.Text Select view
            Case "2"
                query = From view In query Where view.Column7.StartsWith(TextBox7.Text) Select view
            Case "3"
                query = From view In query Where view.Column7.EndsWith(TextBox7.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList8.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column8.Contains(TextBox8.Text) Select view
            Case "1"
                query = From view In query Where view.Column8 = TextBox8.Text Select view
            Case "2"
                query = From view In query Where view.Column8.StartsWith(TextBox8.Text) Select view
            Case "3"
                query = From view In query Where view.Column8.EndsWith(TextBox8.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList9.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column9.Contains(TextBox9.Text) Select view
            Case "1"
                query = From view In query Where view.Column9 = TextBox9.Text Select view
            Case "2"
                query = From view In query Where view.Column9.StartsWith(TextBox9.Text) Select view
            Case "3"
                query = From view In query Where view.Column9.EndsWith(TextBox9.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList10.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column10.Contains(TextBox10.Text) Select view
            Case "1Column10"
                query = From view In query Where view.Column10 = TextBox10.Text Select view
            Case "2"
                query = From view In query Where view.Column10.StartsWith(TextBox10.Text) Select view
            Case "3"
                query = From view In query Where view.Column10.EndsWith(TextBox10.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList11.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column11.Contains(TextBox11.Text) Select view
            Case "1"
                query = From view In query Where view.Column11 = TextBox11.Text Select view
            Case "2"
                query = From view In query Where view.Column11.StartsWith(TextBox11.Text) Select view
            Case "3"
                query = From view In query Where view.Column11.EndsWith(TextBox11.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList12.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column12.Contains(TextBox12.Text) Select view
            Case "1"
                query = From view In query Where view.Column12 = TextBox12.Text Select view
            Case "2"
                query = From view In query Where view.Column12.StartsWith(TextBox12.Text) Select view
            Case "3"
                query = From view In query Where view.Column12.EndsWith(TextBox12.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList13.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column13.Contains(TextBox13.Text) Select view
            Case "1"
                query = From view In query Where view.Column13 = TextBox13.Text Select view
            Case "2"
                query = From view In query Where view.Column13.StartsWith(TextBox13.Text) Select view
            Case "3"
                query = From view In query Where view.Column13.EndsWith(TextBox13.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList14.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column14.Contains(TextBox14.Text) Select view
            Case "1"
                query = From view In query Where view.Column14 = TextBox14.Text Select view
            Case "2"
                query = From view In query Where view.Column14.StartsWith(TextBox14.Text) Select view
            Case "3"
                query = From view In query Where view.Column14.EndsWith(TextBox14.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select

        Select Case DropDownList15.SelectedValue
            Case "-1"
                ''//Do nothing (same as else)
            Case "0"
                query = From view In query Where view.Column15.Contains(TextBox15.Text) Select view
            Case "1"
                query = From view In query Where view.Column15 = TextBox15.Text Select view
            Case "2"
                query = From view In query Where view.Column15.StartsWith(TextBox15.Text) Select view
            Case "3"
                query = From view In query Where view.Column15.EndsWith(TextBox15.Text) Select view
            Case Else
                ''//Do nothing (same as Any).
        End Select


        GridView1.DataSource = query
        GridView1.DataBind()
    End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:54:21+00:00Added an answer on May 30, 2026 at 10:54 am

    Note that Dynamic LINQ is not prone to SQL injection in the same way as a query concatenated from user supplied strings. The string passed is tokenized and parsed to create the expression tree which will be translated into a query, and it doesn’t support an unlimited number of operations.

    You cannot drop a table using a Dynamic LINQ query, for example.

    Still, it is important to note that you need to use Dynamic LINQ with parameter placeholders (or “named parameters”). This has same benefits as using named parameters with a DBComand.


    Also, you can check out PredicateBuilder by Albahari.

    It allows you to convert a static expression like this:

    p => p.Price > 100 &&
         p.Price < 1000 &&
        (p.Description.Contains ("foo") || p.Description.Contains ("far"))
    

    Into this:

    var outer = PredicateBuilder.True<Product>();
    outer = outer.And (p => p.Price > 100);
    outer = outer.And (p => p.Price < 1000);
    {
       var inner = PredicateBuilder.False<Product>();
       inner = inner.Or (p => p.Description.Contains ("foo"));
       inner = inner.Or (p => p.Description.Contains ("far"));
       outer = outer.And (inner);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Solved, with code I got it working, see my answer below for the
UPDATE : The issue was col1 was hiereachyid type and even a select didnt
Update: Thanks for everyone who helped out - the answer to this one lay
UPDATE : Answer at the bottom. Hi Guys, How to initialize an 'array of
UPDATE users u JOIN (select count(*) as job_count, user_id from job_responses where date_created >
UPDATE: Skip to the answer if you want to save yourself the lengthy preamble.
Update Table1 set name = (select top 1 a.col from Table2 a where Table1.num
Update: Oh good grief, it was all a red herring following a bad merge.
Update Mr Wizard's answer gives pixel-perfect results, but it is Windows-only and destroys the
UPDATE 11/18/2011 Check the accepted answer. It works and its a life saver! Hey

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.