feat: ottimizza interfaccia query personalizzate rimuovendo messaggi verbosi
- Rimossi messaggi di successo per validazione query per ridurre ingombro visivo - Eliminati alert informativi delle colonne rilevate dalla query - Rimossa notificazione "Query validata!" nella sezione mapping - Mantenuti solo i messaggi di errore quando necessario - Migliorata UX con interfaccia più pulita e focalizzata sull'essenziale - Funzionalità di estrazione colonne e mapping completamente preservata
This commit is contained in:
@@ -19,7 +19,7 @@ namespace DataConnection.EF;
|
||||
public class EFCoreDatabaseManager : IDatabaseManager
|
||||
{
|
||||
private readonly DbManagerOptions _options;
|
||||
private ExistingDatabaseContext _context;
|
||||
private ExistingDatabaseContext _context = null!;
|
||||
|
||||
public EFCoreDatabaseManager(DbManagerOptions options)
|
||||
{
|
||||
@@ -54,8 +54,8 @@ public class EFCoreDatabaseManager : IDatabaseManager
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetAsync<T>(
|
||||
Expression<Func<T, bool>> filter = null,
|
||||
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
|
||||
Expression<Func<T, bool>>? filter = null,
|
||||
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
|
||||
string includeProperties = "",
|
||||
int? skip = null,
|
||||
int? take = null) where T : class
|
||||
@@ -91,7 +91,7 @@ public class EFCoreDatabaseManager : IDatabaseManager
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<T> GetByIdAsync<T>(object id) where T : class
|
||||
public async Task<T?> GetByIdAsync<T>(object id) where T : class
|
||||
{
|
||||
return await _context.Set<T>().FindAsync(id);
|
||||
}
|
||||
@@ -101,6 +101,43 @@ public class EFCoreDatabaseManager : IDatabaseManager
|
||||
return await _context.Set<T>().FromSqlRaw(sql, parameters).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Dictionary<string, object>>> ExecuteRawQueryAsync(string sql, params object[] parameters)
|
||||
{
|
||||
using var command = _context.Database.GetDbConnection().CreateCommand();
|
||||
command.CommandText = sql;
|
||||
|
||||
// Aggiungi i parametri
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
var parameter = command.CreateParameter();
|
||||
parameter.ParameterName = $"@p{i}";
|
||||
parameter.Value = parameters[i] ?? DBNull.Value;
|
||||
command.Parameters.Add(parameter);
|
||||
}
|
||||
|
||||
await _context.Database.OpenConnectionAsync();
|
||||
|
||||
var results = new List<Dictionary<string, object>>();
|
||||
|
||||
using var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
var row = new Dictionary<string, object>();
|
||||
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
{
|
||||
var columnName = reader.GetName(i);
|
||||
var value = reader.IsDBNull(i) ? null : reader.GetValue(i);
|
||||
row[columnName] = value ?? ""; // Usa stringa vuota invece di null
|
||||
}
|
||||
|
||||
results.Add(row);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public async Task<int> ExecuteCommandAsync(string sql, params object[] parameters)
|
||||
{
|
||||
return await _context.Database.ExecuteSqlRawAsync(sql, parameters);
|
||||
|
||||
@@ -25,8 +25,8 @@ public interface IDatabaseManager : IDisposable
|
||||
/// <param name="skip">Numero di elementi da saltare</param>
|
||||
/// <param name="take">Numero di elementi da prendere</param>
|
||||
Task<IEnumerable<T>> GetAsync<T>(
|
||||
Expression<Func<T, bool>> filter = null,
|
||||
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
|
||||
Expression<Func<T, bool>>? filter = null,
|
||||
Func<IQueryable<T>, IOrderedQueryable<T>>? orderBy = null,
|
||||
string includeProperties = "",
|
||||
int? skip = null,
|
||||
int? take = null) where T : class;
|
||||
@@ -34,13 +34,18 @@ public interface IDatabaseManager : IDisposable
|
||||
/// <summary>
|
||||
/// Ottiene un'entità singola in base alla chiave primaria
|
||||
/// </summary>
|
||||
Task<T> GetByIdAsync<T>(object id) where T : class;
|
||||
Task<T?> GetByIdAsync<T>(object id) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Esegue una query SQL raw
|
||||
/// </summary>
|
||||
Task<IEnumerable<T>> ExecuteQueryAsync<T>(string sql, params object[] parameters) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Esegue una query SQL raw e restituisce i risultati come dictionary
|
||||
/// </summary>
|
||||
Task<List<Dictionary<string, object>>> ExecuteRawQueryAsync(string sql, params object[] parameters);
|
||||
|
||||
/// <summary>
|
||||
/// Esegue un comando SQL che non restituisce risultati
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user