【发布时间】:2015-06-10 06:55:39
【问题描述】:
我正在尝试使用 Azure 移动服务为异步多人游戏创建后端。我在 WAMS 上使用 sql 数据库和 .NET 后端,从 .NET 客户端(Xamarin.iOS 特别是 atm)调用服务。
进入数据库的项目的类:
public class Match {
public string Id { get; set; }
public int Challengers { get; set; }
string GameData { get; set; }
public List<string> Players { get; set; }
public string LastPlayer { get; set; }
public string Message { get; set; }
public string NextPlayer { get; set; }
public int PlayerGroup { get; set; }
}
我将它插入到数据库中:
var matchtable = MobileService.GetTable <Match> ();
CurrentMatch = new Match {
Message = variant.ToString () + ", " + CurrentUser + " vs ??",
NextPlayer = CurrentUser,
Players = players,
PlayerGroup = playerGroup,
Challengers = 0,
Game = null,
LastPlayer = null
};
await matchtable.InsertAsync (CurrentMatch);
然后我正在做其他会影响匹配的事情,并且需要稍后再次更新它,但我没有 CurrentMatch 的 Id 字段来进行更新。我能找到的一切都告诉我应该在插入后取回 Id 字段(方法返回某些东西或用它更新 CurrentMatch 本身),但它必须都在谈论 javascript 后端或不同的客户端或其他东西。 .NET 客户端中的 InsertAsync 方法没有返回值(嗯,技术上返回 Task),并且 CurrentMatch 不会使用调用中的 Id 字段进行更新(也很有意义,因为它不是 ref 或 out 参数)。
我到底应该如何获取刚刚插入数据库的对象的 Id 字段?
【问题讨论】:
标签: c# .net azure azure-sql-database azure-mobile-services