Fix integrazione preliminare servizi utils.stats x IOC:
- aggiunta migrations - correzioni versione ef6 da ef8 - correzioni init varie
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository
|
||||
{
|
||||
public abstract class BaseRepository : IBaseRepository
|
||||
{
|
||||
#region Protected Fields
|
||||
|
||||
protected readonly IDbContextFactory<MoonPro_UtilsContext> _ctxFactory;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Constructors
|
||||
|
||||
protected BaseRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory)
|
||||
=> _ctxFactory = ctxFactory;
|
||||
|
||||
#endregion Protected Constructors
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creazione dbcontext per singola transazione
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<MoonPro_UtilsContext> CreateContextAsync()
|
||||
=> await _ctxFactory.CreateDbContextAsync();
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Salvataggio dati asincrono
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<bool> SaveChangesAsync(DataLayerContext ctx)
|
||||
=> await ctx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#if false
|
||||
protected readonly DataLayerContext _dbCtx;
|
||||
protected BaseRepository(DataLayerContext db) => _dbCtx = db;
|
||||
public async Task<bool> SaveChangesAsync() => await _dbCtx.SaveChangesAsync() > 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MP.Data.Repository
|
||||
{
|
||||
public interface IBaseRepository
|
||||
{
|
||||
//Task<DataLayerContext> CreateContextAsync();
|
||||
//Task<bool> SaveChangesAsync(DataLayerContext ctx);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
using EgwCoreLib.Utils;
|
||||
using MP.Data.DbModels.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Utils
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using EgwCoreLib.Utils;
|
||||
using MP.Data.DbModels.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Utils
|
||||
{
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
using EgwCoreLib.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Data.DbModels.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Utils
|
||||
{
|
||||
@@ -6,7 +12,7 @@ namespace MP.Data.Repository.Utils
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsAggrRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
||||
public StatsAggrRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory) : base(ctxFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,11 +64,20 @@ namespace MP.Data.Repository.Utils
|
||||
{
|
||||
DateTime startDate = firstRec.Hour;
|
||||
DateTime endDate = lastRec.Hour;
|
||||
// uso direttamente ExecuteDelete
|
||||
|
||||
// uso direttamente ExecuteDelete quando in EFCore8...
|
||||
#if false
|
||||
await dbCtx
|
||||
.DbSetStatsAggr
|
||||
.Where(x => x.Hour >= startDate && x.Hour <= endDate)
|
||||
.ExecuteDeleteAsync();
|
||||
#endif
|
||||
var items = await dbCtx.DbSetStatsAggr
|
||||
.Where(x => x.Hour >= startDate && x.Hour <= endDate)
|
||||
.ToListAsync();
|
||||
|
||||
dbCtx.DbSetStatsAggr.RemoveRange(items);
|
||||
await dbCtx.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
using EgwCoreLib.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MP.Data.DbModels.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.Utils
|
||||
{
|
||||
@@ -6,7 +12,7 @@ namespace MP.Data.Repository.Utils
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public StatsDetailRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
||||
public StatsDetailRepository(IDbContextFactory<MoonPro_UtilsContext> ctxFactory) : base(ctxFactory)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,11 +85,20 @@ namespace MP.Data.Repository.Utils
|
||||
{
|
||||
DateTime startDate = firstRec.Hour;
|
||||
DateTime endDate = lastRec.Hour;
|
||||
// uso direttamente ExecuteDelete
|
||||
await dbCtx
|
||||
.DbSetStatsDet
|
||||
.Where(x => x.Hour >= startDate && x.Hour <= endDate)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
// uso direttamente ExecuteDelete quando in EFCore8...
|
||||
#if false
|
||||
await dbCtx
|
||||
.DbSetStatsDet
|
||||
.Where(x => x.Hour >= startDate && x.Hour <= endDate)
|
||||
.ExecuteDeleteAsync();
|
||||
#endif
|
||||
var items = await dbCtx.DbSetStatsDet
|
||||
.Where(x => x.Hour >= startDate && x.Hour <= endDate)
|
||||
.ToListAsync();
|
||||
|
||||
dbCtx.DbSetStatsDet.RemoveRange(items);
|
||||
await dbCtx.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user