更新时间:2023-10-23 13:01:46
我面临着同样的问题。使用任何或包含如其他人所说给了我一个不支持异常。我贴在Azure移动服务论坛,被告知不支持呢。他们建议我用它完美地工作对我来说是扩展方法。下面是code我用。
I faced the same issue. Using Any or Contains as others have suggested gave me a Not Supported Exception. I posted on the Azure Mobile Services forum and was told that IN is not supported yet. They advised I use an extension method which worked perfectly for me. Below is the code I used.
public static class Extensions
{
public async static Task<List<T>> In<T>(this IMobileServiceTable<T> table, List<int> ids)
{
var query = new StringBuilder("$filter=(");
for (int i = 0; i < ids.Count; i++)
{
query.AppendFormat("id eq {0}", ids[i]); //don't forget to url escape and 'quote' strings
if (i < ids.Count - 1)
{
query.Append(" or ");
}
}
query.Append(")");
var list = await table.ReadAsync(query.ToString());
var items = list.Select(i => MobileServiceTableSerializer.Deserialize<T>(i)).ToList();
return items;
}
}
您列表可以填充通过调用这样的扩展方法:
Your list can be populated by calling the extension method like this:
FavoriteJokesList = await jokeItemTable.In(favoriteJokeIds);
来源:http://social.msdn.microsoft.com/Forums/en-US/azuremobile/thread/b573ff6c-1f6b-4846-b44d-4678e3d26f66