C# 如何将多个记录异步提交到数据库?

C# 如何将多个记录异步提交到数据库?,c#,performance,azure,scalability,record,C#,Performance,Azure,Scalability,Record,我在点击按钮时使用以下方法将记录添加到Azure数据中。但我想知道,在性能和可伸缩性方面,是否有更好的方法将数据提交到数据库,而无需为每个新记录创建新项 这就是我当前向Azure移动服务提交数据的方式: Item itemOne = new Item { Repititions = " " + fingersSpreadScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm

我在点击按钮时使用以下方法将记录添加到Azure数据中。但我想知道,在性能和可伸缩性方面,是否有更好的方法将数据提交到数据库,而无需为每个新记录创建新项

这就是我当前向Azure移动服务提交数据的方式:

            Item itemOne = new Item { Repititions = " " + fingersSpreadScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm tt"), User = "Ted Bundy" , Exercise = "Fingers Spread"};
            await App.MobileService.GetTable<Item>().InsertAsync(itemOne);

            Item itemTwo = new Item { Repititions = " " + fistHeldScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm tt"), User = "Joe Bloggs", Exercise = "Fist Held" };
            await App.MobileService.GetTable<Item>().InsertAsync(itemTwo);

            Item itemThree = new Item { Repititions = " " + waveOutScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm tt"), User = "George Bush", Exercise = "Wrist Extension" };
            await App.MobileService.GetTable<Item>().InsertAsync(itemThree);
Item itemOne=new Item{Repititions=“+fingersSpreadScoreCntr.ToString(),Date=“+DateTime.Now.ToString”(@“MM\/dd\/yyyyy h\:MM tt)),User=“Ted Bundy”,Exercise=“Fingers Spread”};
等待App.MobileService.GetTable().InsertAsync(itemOne);
Item itemTwo=新项{Repititions=“”+fistHeldScoreCntr.ToString(),Date=“+DateTime.Now.ToString(@“MM\/dd\/yyyyy h\:MM tt)),User=“Joe Bloggs”,Exercise=“Fist Hold”};
等待App.MobileService.GetTable().InsertAsync(itemTwo);
Item itemThree=新项目{Repititions=”“+waveOutScoreCntr.ToString(),Date=“+DateTime.Now.ToString(@“MM\/dd\/yyyyy h\:MM tt)),User=“George Bush”,Exercise=“手腕伸展”};
等待App.MobileService.GetTable().InsertAsync(itemThree);

据我所知,移动服务表中没有批量插入功能。 加速多个插入的一个方法是异步并行执行它们。在代码示例中,您正在等待(
wait
)每个
InsertAsync
在开始下一个之前完成。调用所有插入然后等待它们全部完成会更快。示例代码可能如下所示:

        var table = App.MobileService.GetTable<Item>();
        Item itemOne = new Item { Repititions = " " + fingersSpreadScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm tt"), User = "Ted Bundy", Exercise = "Fingers Spread" };
        Item itemTwo = new Item { Repititions = " " + fistHeldScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm tt"), User = "Joe Bloggs", Exercise = "Fist Held" };
        Item itemThree = new Item { Repititions = " " + waveOutScoreCntr.ToString(), Date = " " + DateTime.Now.ToString(@"MM\/dd\/yyyy h\:mm tt"), User = "George Bush", Exercise = "Wrist Extension" };

        await Task.WhenAll(
            table.InsertAsync(itemOne),
            table.InsertAsync(itemTwo),
            table.InsertAsync(itemThree));
var table=App.MobileService.GetTable();
Item itemOne=新项目{Repititions=”“+FingersPreadsCoreContr.ToString(),Date=“+DateTime.Now.ToString(@“MM\/dd\/yyyyy h\:MM tt”),User=“Ted Bundy”,Exercise=“Fingers Spread”};
Item itemTwo=新项{Repititions=“”+fistHeldScoreCntr.ToString(),Date=“+DateTime.Now.ToString(@“MM\/dd\/yyyyy h\:MM tt)),User=“Joe Bloggs”,Exercise=“Fist Hold”};
Item itemThree=新项目{Repititions=”“+waveOutScoreCntr.ToString(),Date=“+DateTime.Now.ToString(@“MM\/dd\/yyyyy h\:MM tt)),User=“George Bush”,Exercise=“手腕伸展”};
等待任务(
表.InsertAsync(itemOne),
表.InsertAsync(第二项),
表.InsertAsync(第三项);
这样,您还可以消除每次插入后不必要的上下文切换

批量插入“*将数据提交到数据库而不为每个新记录创建新项*”是什么意思?