31 lines
907 B
C#
31 lines
907 B
C#
using EFCore.BulkExtensions;
|
|
using Hcs.WebApp.Data.Hcs;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hcs.WebApp.Services
|
|
{
|
|
public class AccountService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
|
{
|
|
public async Task<IEnumerable<Account>> GetAllAccountsAsync()
|
|
{
|
|
using var context = GetNewContext();
|
|
return await context.Accounts.ToListAsync();
|
|
}
|
|
|
|
public async Task UpsertAccounts(HcsDbContext context, IEnumerable<Account> accounts)
|
|
{
|
|
await context.BulkInsertOrUpdateAsync(accounts, new BulkConfig()
|
|
{
|
|
PropertiesToExcludeOnUpdate =
|
|
[
|
|
nameof(Account.ThirdPartyId)
|
|
],
|
|
UpdateByProperties =
|
|
[
|
|
nameof(Account.HcsId)
|
|
]
|
|
});
|
|
}
|
|
}
|
|
}
|