Windows Azure移动服务查询表
我使用Windows Azure移动服务。 我有一个元素表。 我要查询的云数据库:Windows Azure移动服务查询表
- 选择ID,名称 从单元ORDER BY创建时间
但我不会在所有的“查询”使用Windows Azure移动服务系统了解。 我有一个IMobileServiceTable,但不知道该怎么办...
我检查了教程,他们解释如何使用Where子句,但不选择。我需要选择只有某些列,因为我的元素有图片,我不想下载它在我GETALL方法....
编辑:
我尝试:
Task.Factory.StartNew(() =>
{
var query = table.Select(x =>
new Element()
{
Id = x.Id,
Name = x.Name,
Price = x.Price
});
var _items = query.ToListAsync().Result;
}).ContinueWith((x) => handleProductsArrived(x.Result));
但它不起作用。
如果你使用.net,你几乎可以遵循linq。 在研究样本应用程序 - 它有 -
private void RefreshTodoItems()
{
// This code refreshes the entries in the list view be querying the TodoItems table.
// The query excludes completed TodoItems
items = todoTable
.Where(todoItem => todoItem.Complete == false)
.ToCollectionView();
ListItems.ItemsSource = items;
}
如果,例如,你不希望你可以在电话前加上完整的标志返回.ToCollectionView()
.Select(item=>new {item.Id, item.Text})
这将创建指定两个成员的匿名类型的新对象(可以是具体类型)的列表。
我在第一篇文章中添加了一些细节。 – Roroto 2013-02-15 09:50:37
你可以找到卡洛斯一个有用的职位,其中包括相应的SQL查询是什么在这里:http://blogs.msdn.com/b/carlosfigueira/archive/2012/09/21/playing-with-the-query-object-in-read-operations-on-azure-mobile-services.aspx
例如:
function read(query, user, request) {
query.where({ UserId: user.userId })
.select('id', 'MovieName', 'MovieRating')
.orderBy('MovieName')
.take(10);
request.execute();
}
woudld转化为
SELECT TOP 10 [ID ],[MovieName],[MovieRating] FROM MovieRating WHERE Rating> 2和UserId =? ORDER BY的movieName
所以对于你的情况,你需要翻译
选择ID,名称 从单元 ORDER BY创建时间
你会去的东西,如下列:
function read(query, user, request) {
query.where({ UserId: user.userId })
.select('id', 'Name', 'Element')
.orderBy('creationTime')
request.execute();
}
这听起来像你只是想用IMobileServiceTable
做一个简单的查询
SELECT Id, Name FROM Element ORDER BY creationTime
如果你不介意使用IMobileServiceTable<TodoItem>
,你可以尝试:
1)拆除成员属性,你不会从你的对象需要
例子:
public class TodoItem
{
public int Id { get; set; }
// REMOVE WHAT YOU DO NOT WANT
//[DataMember(Name = "text")]
//public string Text { get; set; }
[DataMember(Name = "complete")]
public bool Complete { get; set; }
}
2)以下是读取数据的代码:
private void RefreshTodoItems()
{
items = todoTable
.OrderBy(todoItem => todoItem.Id)
.Take(10)
.ToCollectionView();
ListItems.ItemsSource = items;
}
这是基本上是:
SELECT TOP 10 Id, Complete FROM TodoTable ORDER BY Id
为todoTable的代码示例是在http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-wp8/
希望这有助于。
你使用的是.net还是javascript? – 2013-02-13 16:06:42
.net(xamarin,c#) – Roroto 2013-02-15 11:07:44