本文整理汇总了C#中Db.SaveChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Db.SaveChangesAsync方法的具体用法?C# Db.SaveChangesAsync怎么用?C# Db.SaveChangesAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db.SaveChangesAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrCreatePlayer
private async Task<Models.Player> GetOrCreatePlayer(string name, League league, Db db)
{
var playerQuery = db.Players.Where(x => x.LeagueId == league.Id);
var player = await playerQuery.FirstOrDefaultAsync(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
if (player == null)
{
player = new Models.Player
{
LeagueId = league.Id,
Name = name
};
db.Players.Add(player);
await db.SaveChangesAsync();
}
return player;
}
示例2: CreateGame
private async Task<Game> CreateGame(int redScore, int blueScore, League league, Db db)
{
var game = new Game
{
BlueScore = blueScore,
RedScore = redScore,
Date = DateTime.UtcNow,
LeagueId = league.Id
};
db.Games.Add(game);
await db.SaveChangesAsync();
return game;
}
示例3: CreatePosition
private async Task CreatePosition(Game game, Models.Player player, PlayerPositionTypes position, Db db)
{
db.PlayerPositions.Add(new PlayerPosition
{
GameId = game.Id,
PlayerId = player.Id,
Position = position
});
await db.SaveChangesAsync();
}