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 8046011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:41:25+00:00 2026-06-05T05:41:25+00:00

I am building a dynamic query builder using the dynamic linq library. SO far

  • 0

I am building a dynamic query builder using the dynamic linq library.
SO far its working fine with bool, number and text, but not with dates.

I wonder what should be the format for dates to work fine.

THis is the code that executes what sb.ToString returns.

private string BuildQuery()
        {
            var sb = new StringBuilder();
            //var list = RequestBaseBL.GetRequestByCustomQuery("RequestNumber == \"12\"");
        #region 1st ROW of the QUERY
        if (ColumnType(DdlColumn1.SelectedValue) == "Text")
        {
            if(DdlOperator1.SelectedValue == "==")
            {
                sb.Append(DdlColumn1.SelectedValue);
                sb.Append(DdlOperator1.SelectedValue);
                sb.Append("\"" + TxtValue1.Text + "\"");
            }
            if (DdlOperator1.SelectedValue == "<>")
            {
                sb.Append(DdlColumn1.SelectedValue);
                sb.Append(DdlOperator1.SelectedValue);
                sb.Append("\"" + TxtValue1.Text + "\"");
            }
            if (DdlOperator1.SelectedValue == "LIKE")
            {
                sb.Append(string.Format("{0}.Contains(\"{1}\")", DdlColumn1.SelectedValue, TxtValue1.Text));
            }
            if (DdlOperator1.SelectedValue == "NOT LIKE")
            {
                sb.Append(string.Format("!{0}.Contains(\"{1}\")", DdlColumn1.SelectedValue, TxtValue1.Text));
            }
        }

        if (ColumnType(DdlColumn1.SelectedValue) == "Number")
        {
            sb.Append(DdlColumn1.SelectedValue);
            sb.Append(DdlOperator1.SelectedValue);
            sb.Append(TxtValue1.Text);
        }

        if (ColumnType(DdlColumn1.SelectedValue) == "Date")
        {
            sb.Append(DdlColumn1.SelectedValue);
            sb.Append(DdlOperator1.SelectedValue);
            sb.Append(TxtValue1.Text);
        }

        if (ColumnType(DdlColumn1.SelectedValue) == "Bool")
        {
            sb.Append(DdlColumn1.SelectedValue);
            sb.Append(DdlOperator1.SelectedValue);
            sb.Append(TxtValue1.Text);
        }

        #endregion  


        return sb.ToString();
    }


  string strSql = BuildQuery();
            try
            {
                var list = RequestBaseBL.GetRequestByCustomQuery(strSql, DdlRequestType.SelectedValue).ToList();



private static void AddDateOperatorsToList(Dictionary<string, string> operators)
            {
                operators.Add("=", "Equals");
                operators.Add("<>", "Not Equals");
                operators.Add(">", "Greater than");
                operators.Add(">=", "Greater or equal than");
                operators.Add("<", "Less than");
                operators.Add("<=", "Less or equal than");
            }

Update 1:

The error is:
Operator ‘=’ incompatible with operand types ‘DateTime’ and ‘Int32’

The sb.toString()

? sb.ToString()
“RequestDate=12/12/2015”

Update 2:

Error of Update 2:

No applicable method ‘Parse’ exists in type ‘DateTime’

if (ColumnType(DdlColumn1.SelectedValue) == "Date")
                {
                    sb.AppendFormat("DateTime.Parse({0})", DdlColumn1.SelectedValue);
                    var str = string.Format("{0} {1} {2}", DdlColumn1.SelectedValue, DdlOperator1.SelectedValue,
                                               DateTime.Parse(TxtValue1.Text));
                    //sb.Append(DdlColumn1.SelectedValue);
                    //sb.Append(DdlOperator1.SelectedValue);
                    //sb.Append(TxtValue1.Text);
                    sb.Append(str);
                }

Update 3:

Didnt work either

if (ColumnType(DdlColumn1.SelectedValue) == "Date")
                {
                    var date = DateTime.Parse(TxtValue1.Text);
                    sb.Append(DdlColumn1.SelectedValue);
                    sb.Append(DdlOperator1.SelectedValue);
                    sb.Append("\"" + date.ToUniversalTime() + "\"");
                    //sb.Append(date.ToUniversalTime());
                }

enter image description here

  • 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-06-05T05:41:26+00:00Added an answer on June 5, 2026 at 5:41 am

    I’m currently using System.Dynamic.Linq and use a double equal with a DateTime object.

    case "Equals":
        myDictionary.Add("MyField.Date ==", dt1);
        break;
    

    Later I convert the keys in the dictionary to a string and values to an array (notice the @ symbol usage):

    if (myDictionary.Keys.Count > 0)
    {
      var conditions = myDictionary.Keys.Select((key, idx) => string.Format("{0} (@{1})", key, idx));
    
      // in .NET 4, the ToArray() part can go away
      predicateString = string.Join(" and ", conditions.ToArray());
      predicateValues = myDictionary.Values.ToArray();
    }
    

    Then call AsQueryable().Where()

    return myList.AsQueryable().Where(predicateString, predicateValues).ToList();
    

    I believe doing it this way eliminates the need to deal with the DateTime object as a string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a query with the LINQ dynamic library so I don't know how
Or possibly there is a better way. I am building a dynamic query builder
I'm building dynamic forms in GWT, but I'm not sure how to dynamically retrieve
I'm building a dynamic drop down box for an HTML form using PHP and
I have create a LINQ-to-SQL project in Visual Studio 2010 using Dynamic Data. In
I'm building a dynamic web application in Eclipse using Struts2 and OC4J 10.1.3.3.0. I'm
I have a stored procedure which is building a dynamic sql query and then
We need to produce a fairly complex dynamic query builder for retrieving reports on
Is it possible to use a dynamic Linq Expression inside a Query Expression? Something
I'm building a LINQ-based query generator. One of the features is being able to

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.