-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateRangeStorageQuery.cs
34 lines (31 loc) · 1.05 KB
/
DateRangeStorageQuery.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using Microsoft.WindowsAzure.Storage.Table;
using Queryable = System.Linq.Queryable;
namespace Veggerby.Storage.Azure.Table.Query
{
public class DateRangeStorageQuery<T> : StorageQuery<T> where T: ITableEntity, new()
{
public DateRangeStorageQuery(string fieldId, DateTime? minValue, DateTime? maxValue)
{
if (minValue == null && maxValue == null)
{
throw new ArgumentException("minValue and maxValue cannot both be null", "minValue");
}
if (maxValue == null)
{
Query = Query.Where(
fieldId.GreaterThanOrEqual(minValue.Value));
}
else if (minValue == null)
{
Query = Query.Where(
fieldId.LessThanOrEqual(maxValue.Value));
}
else
{
Query = Query.Where(
fieldId.GreaterThanOrEqual(minValue.Value).And(fieldId.LessThanOrEqual(maxValue.Value)));
}
}
}
}