public async Task <bool> BulkMerge(List <AccountFoodFavorite> AccountFoodFavorites) { List <AccountFoodFavoriteDAO> AccountFoodFavoriteDAOs = new List <AccountFoodFavoriteDAO>(); foreach (AccountFoodFavorite AccountFoodFavorite in AccountFoodFavorites) { AccountFoodFavoriteDAO AccountFoodFavoriteDAO = new AccountFoodFavoriteDAO(); AccountFoodFavoriteDAO.AccountId = AccountFoodFavorite.AccountId; AccountFoodFavoriteDAO.FoodId = AccountFoodFavorite.FoodId; AccountFoodFavoriteDAOs.Add(AccountFoodFavoriteDAO); } await DataContext.BulkMergeAsync(AccountFoodFavoriteDAOs); return(true); }
private async Task SaveReference(Account Account) { await DataContext.AccountFoodFavorite.Where(a => a.AccountId == Account.Id).DeleteFromQueryAsync(); if (Account.AccountFoodFavorites != null) { List <AccountFoodFavoriteDAO> AccountFoodFavoriteDAOs = new List <AccountFoodFavoriteDAO>(); foreach (var AccountFoodFavorite in Account.AccountFoodFavorites) { AccountFoodFavoriteDAO AccountFoodFavoriteDAO = new AccountFoodFavoriteDAO { AccountId = Account.Id, FoodId = AccountFoodFavorite.FoodId }; AccountFoodFavoriteDAOs.Add(AccountFoodFavoriteDAO); } DataContext.AccountFoodFavorite.AddRange(AccountFoodFavoriteDAOs); } await DataContext.SaveChangesAsync(); }