LINQ query against Azure table service fails

NaffieMNaffieM USUniversity ✭✭

I have a few records saved in my Azure Table Storage. I'm trying to pull records from a table,for only a particular day/date, for the currently logged in user.

My query returns nothing, so my list is always empty, even though I know that I have 3 records for this month, in my table.

I'm not sure why the query fails in this case. How do I pull records for a specific date, for a specific user? Any help?

This is what I've tried so far:

` public async Task<Result<List>> FetchAlertsForDate (DateTime date)
{

try {

   var fromDate = new DateTime(date.Year,date.Month,date.Day,0,0,0); //lets create a 12:00:00 AM date

   var toDate = new DateTime(date.Year,date.Month,date.Day,23,59,59); //lets create a 23:59:59PM date

   var alertTable=client.GetSyncTable<Alert>();

   var alerts = await alertTable.Where(n=>n.AccountId==client.CurrentUser.UserId).Where(n=> n.StartDate >= fromDate && n.StartDate <= toDate).ToListAsync();

   return Result<List<Alert>>.Success(alerts);

} catch (Exception ex) {
return Result<List>.Failure (ex.Message + ex.StackTrace);
}

}`

Best Answer

Answers

  • NaffieMNaffieM USUniversity ✭✭

    I have also tried to modify the query to this : var alerts = await alertTable.Where(n=>n.AccountId==client.CurrentUser.UserId).Where(n=> n.StartDate.Date == date.Date).ToListAsync(); But this fails with the following exception: The member 'Date' is not supported in the 'Where' Mobile Services query expression 'n.StartDate.Date'. . Then I modified the query to this : var alerts = await alertTable.Where(n=>n.AccountId==client.CurrentUser.UserId && n.StartDate.Date == date.Date).ToListAsync(); But this doesn't return any records, even though I have 3 records currently.

Sign In or Register to comment.