【问题标题】:how to use between clause in windows phone azure storage.i want to get data in between two dates in windows phone如何在 windows phone azure storage 中使用 between 子句。我想在 windows phone 中的两个日期之间获取数据
【发布时间】:2014-09-19 00:07:26
【问题描述】:

私有异步任务 RunningData() {

// 我想在 windows phone 中使用 azure storage 获取两个日期之间的数据。

        var table = MobileService.GetTable<Tracing>();
        string date1 = "13/09/2014 12:58:42";
        string date2 = "12/09/2014 16:26:55";
        var items = await table
            .Where(Tracing => Tracing.Date == date1 || Tracing.Date==date2 )               
            .Take(PageSize)
            .Skip(this.currentIndex)
            .IncludeTotalCount()
            .ToListAsync();


        this.lstItems.ItemsSource = items;
        int totalCount = (int)((ITotalCountProvider)items).TotalCount;
        this.lblStatus.Text = string.Format("Showing items from position {0} to {1} (of {2})", currentIndex, currentIndex + PageSize - 1, totalCount);
    }

【问题讨论】:

  • 与mysql相关的这里我想知道在.netframework中怎么做
  • 该问题的选定答案具有可在 LINQ 查询中使用的点网扩展方法。这不是 mysql。
  • 那很好,但我想要完全在微软天蓝色存储中。
  • 您的问题并非特定于 Azure 存储,您是在问一个 LINQ 问题——@Jonathan 发布的问题已解决了这个问题。

标签: c# azure windows-phone-8


【解决方案1】:

你可以创建一个扩展方法(感谢Equivalent of SQL Between Statement Using Linq or a Lambda expression):

public static bool IsBetween(this DateTime dt, DateTime start, DateTime end)
{
   return dt >= start && dt <= end;    
}

然后从您的 linq 查询中调用它:

var items = await table
        .Where(Tracing => Tracing.Date.IsBetween(date1, date2))               
        .Take(PageSize)
        .Skip(this.currentIndex)
        .IncludeTotalCount()
        .ToListAsync();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多