我正在尝试使用Azure移动服务为异步多人游戏创建后端。我在WAMS上使用sql数据库和.NET后端,从.NET客户端调用服务(特别是atma的Xamarin.iOS)。
要进入db的项目的类:
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);
我正在做其他会影响匹配的事情,需要稍后再次更新,但我没有Id字段让CurrentMatch能够进行更新。我能找到的一切告诉我,我应该在插入后返回Id字段(方法返回一些东西或用它更新CurrentMatch本身),但它必须都是在讨论javascript后端或不同的客户端或其他东西。 .NET客户端中的InsertAsync方法没有返回值(好吧,技术上返回Task),并且CurrentMatch没有使用调用的Id字段进行更新(也是有意义的,因为它不是ref或out参数)。
我究竟应该为刚插入数据库的对象获取Id字段吗?
答案 0 :(得分:1)
我假设您使用的是最新版本的移动服务客户端SDK,在这种情况下,您将调用此InsertAsync method here。
你说这个参数不是ref或out参数,但它可以修改你传入的对象的字段。在这种情况下,它将修改Match对象的内容。
我的猜测是,还有另一个代码问题正在干扰。或者,如果该代码片段在方法中,请确保它返回一个任务,并在检查Id的内容之前等待它。一个简单的控制台日志应该有帮助。
如果这不能解决问题,那么请包含更多上下文,否则您编写的代码应该像我所说的一样。