I am using Dynamic linq to provide my MVC app with data and I have trouble with DateTime fields.
The objects I'm parsing through has a System.Datetime field and I want to check if the dates correspond.
So I try to build the string like this (I'm parsing through a dynamic dictionary to get the data):
string dateToParse = keyValuePair.Value;
DateTime objDate = DateTime.Parse(dateToParse);
valuesToUse.Add("OBJ_DATE.Date == " + objDate.ToShortDateString());
And when I load the data, I do it like this:
var objQry = from pl in m_Db.OBJS.Where(whereConditions)
select pl;
The whereConditions
variable is a string I build when I have all the data.
But when the data hits the datetime field, the app crashes with the following statement:
Operator '==' incompatible with operand types 'DateTime' and 'Int32'
How can I check a DateTime field using dynamic Linq? I have tried many options, like putting the objDate without ToShortDateString, but with the same effect.
EDIT:
"OBJ_DATE.Date == 2012.01.01", for example