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

  • Home
  • SEARCH
  • 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 8727867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:31:12+00:00 2026-06-13T08:31:12+00:00

I am using dynamic where clause with Entity Framework 4.0 to filter the results.

  • 0

I am using dynamic where clause with Entity Framework 4.0 to filter the results.

Like

ObjectQuery<T> tmp =  _context.MyTable.where("it.CreatedAt = @p0");

@p0 is a object parameter

This works perfectly fine.

But the problem is i want to something like:

where("CAST(it.CreatedAt as Date) = @p0");

And
where(“SqlServer.CAST(it.CreatedAt as Date) = @p0”);

Both of them failed.

Any help is appreciated

UPDATE:

Error Info:

Type ‘Date’ could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly.

And the where query is

 it.IsDeleted = true  and (  it.OrganizationName ='05 sep 2012' OR  Cast( it.CreatedAt as Date )  =@p4 OR  1=0 ) 

The Object Parameter is already supplied.

The value currently passing is ‘9/5/2012 12:00:00 AM’
and Like:

string temp = SearchedQuery.Trim();
 DateTime res;
 if (DateTime.TryParse(temp, out res))
{
 query += ((" Cast( it." + field.Name +  " as Date )  =@p" + i + ""));

 ObjectParameter pr = new ObjectParameter("p" + i, res);

 param.Add(pr);

 query += " OR ";
}
  • 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-13T08:31:13+00:00Added an answer on June 13, 2026 at 8:31 am

    This worked for me. This is not perfect but worked in some case in which i want. We can clean it more also

     string temp = SearchedQuery.Trim();
     DateTime res;
     if (DateTime.TryParse(temp, out res))
     {
     query += ((" ( it." + field.Name + " >@p" + i + ""));
    
     query += " AND ";
    
     ObjectParameter pr = new ObjectParameter("p" + i, res);
    
     i++;
    
     query += ((" it." + field.Name + " <@p" + i + " ) "));
    
     ObjectParameter pr1 = new ObjectParameter("p" + i, res.AddDays(1));
    
     param.Add(pr);
     param.Add(pr1);
    
    
     query += " OR ";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a completely dynamic way to query entity framework using
I have just create a very basic Dynamic Data web application using Entity Framework,
I have started using the entity framework for a web application and would like
I would like to write a hql query using a dynamic instantiation with a
I would like to execute a LINQ query with a dynamic where clause depending
Possible Duplicate: Need help in dynamic query with IN Clause I am using SQL
What i think is that dynamic type means dynamically allocated object using new .
I'm trying to generate a dynamic property in a framework I'm using, and I'm
I am using System.Linq.Dynamic to do custom where clauses from an ajax call in
i am trying to create a dynamic multioption select using dynamic values for a

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.