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 ";
}
This worked for me. This is not perfect but worked in some case in which i want. We can clean it more also