Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用.NET客户端for Azure Mobile获取新插入项目的Id字段_C#_.net_Azure_Azure Sql Database_Azure Mobile Services - Fatal编程技术网

C# 如何使用.NET客户端for Azure Mobile获取新插入项目的Id字段

C# 如何使用.NET客户端for Azure Mobile获取新插入项目的Id字段,c#,.net,azure,azure-sql-database,azure-mobile-services,C#,.net,Azure,Azure Sql Database,Azure Mobile Services,我正在尝试使用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<str

我正在尝试使用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; }
}
公共类匹配{
公共字符串Id{get;set;}
公共int挑战者{get;set;}
字符串GameData{get;set;}
公共列表玩家{get;set;}
公共字符串LastPlayer{get;set;}
公共字符串消息{get;set;}
公共字符串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);
var matchtable=mobileseservice.GetTable();
当前匹配=新匹配{
Message=variant.ToString()+,“+CurrentUser+”vs???”,
NextPlayer=CurrentUser,
玩家=玩家,
PlayerGroup=PlayerGroup,
挑战者=0,
Game=null,
LastPlayer=null
};
等待matchtable.InsertAsync(CurrentMatch);
然后我会做其他会影响匹配的事情,需要在以后再次更新,但是我没有一个Id字段让CurrentMatch能够进行更新。我所能找到的一切都告诉我,我应该在插入后返回Id字段(方法返回某个内容或更新CurrentMatch本身),但它必须是关于javascript后端或不同的客户端或其他内容。.NET客户端中的InsertAsync方法没有返回值(从技术上讲,返回任务),并且CurrentMatch不会使用调用中的Id字段进行更新(因为它不是ref或out参数,所以也是有意义的)


我究竟应该如何获取刚刚插入数据库的对象的Id字段?

我假设您使用的是最新版本的移动服务客户端SDK,在这种情况下,您可以调用它

没错,该参数不是ref或out参数,但它可以修改传入对象的字段。在这种情况下,它将修改Match对象的内容

我的猜测是,还有另一个干扰的代码问题。或者,如果该代码段位于某个方法中,请确保它返回一个任务,并在检查Id的内容之前等待该任务。简单的控制台日志在这里会有所帮助

如果这不能解决问题,那么请包含更多的上下文,否则您编写的代码应该像我说的那样