32 lines
914 B
C#
32 lines
914 B
C#
using EFCore.BulkExtensions;
|
|
using Hcs.WebApp.Data.Hcs;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hcs.WebApp.Services
|
|
{
|
|
public class HouseService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
|
{
|
|
public async Task<IEnumerable<House>> GetAllHousesAsync()
|
|
{
|
|
using var context = GetNewContext();
|
|
return await context.Houses.ToListAsync();
|
|
}
|
|
|
|
public async Task UpsertHouses(IEnumerable<House> houses)
|
|
{
|
|
using var context = GetNewContext();
|
|
await context.BulkInsertOrUpdateAsync(houses, new BulkConfig()
|
|
{
|
|
PropertiesToExcludeOnUpdate =
|
|
[
|
|
nameof(House.ThirdPartyId)
|
|
],
|
|
UpdateByProperties =
|
|
[
|
|
nameof(House.HcsId)
|
|
]
|
|
});
|
|
}
|
|
}
|
|
}
|