Reputation: 1555
I have a silverlight application which is going in one of my CRM dashboards, it needs to check whether or not a specified date is equal to the date on the record, it also needs to check whether or not one of the fields on the record is an empty string:
private void SearchContacts(Nullable<DateTime> date)
{
try
{
DateTime UpdatedTime = date ?? DateTime.Now;
DataServiceQuery<myentity> query = (DataServiceQuery<myentity>)_context.myentitySet.AddQueryOption("$filter", "((my_ForMonthEnding eq '" + UpdatedTime.ToString() + "') and (my_ActionDetails eq ''))");
query.BeginExecute(OnMyEntitySearchComplete, query);
}
catch (SystemException ex)
{
_syncContext.Send(new SendOrPostCallback(showErrorDetails), ex);
}
}
This code generates the following error:
Operator 'eq' incompatible with operand types 'System.Nullable'
This seems odd to me as I'm casting the nullable DateTime to a standard DateTime, so I must be missing something. Can someone please explain what it is In eed to do here?
Upvotes: 0
Views: 593
Reputation: 1555
This is the query I used which worked:
DataServiceQuery<myentity> query = (DataServiceQuery<myentity>)_context.myEntitySet.Where(c => c.my_ForMonthEnding == date && c.my_ActionDetails.Equals(null));
query.BeginExecute(OnContactSearchComplete, query);
Upvotes: 1
Reputation: 18895
Never worked with Silverlight or DataServiceQuery before so this may be a stab in the dark, but my_ForMonthEnding
would be a nullable
type. Can you try changing it to my_ForMonthEnding.Value
?
Ok, so it looks like you're generating an OData URL using the DataServiceQuery. Here is an example Filter that I created using LinqPad:
$filter=(CreatedOn eq datetime'2012-11-14T11:18:38.4769698-05:00') and (my_name eq '')
CreatedOn is a DateTime?
, and this works just fine. Can you try adding datetime in front of your string date and removing your outside parenthesis?
DataServiceQuery<myentity> query = (DataServiceQuery<myentity>)_context.myentitySet
.AddQueryOption("$filter", "(my_ForMonthEnding eq datetime'" + UpdatedTime.ToString() + "') and (my_ActionDetails eq '')");
query.BeginExecute(OnMyEntitySearchComplete, query);
Upvotes: 0