npgsql 适配临时提交
continuous-integration/drone/push Build is passing

This commit is contained in:
hang
2024-09-02 23:35:42 +08:00
parent e8db8a892c
commit 01ee530e38
7 changed files with 181 additions and 148 deletions
@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IRaCIS.Core.Infra.EFCore.Common.Dto
{
public class AnswerDto
{
public string QuestionName { get; set; }
public string Answer { get; set; }
}
}
@@ -1,17 +0,0 @@
using IRaCIS.Core.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore.Common.Dto
{
public class AuditingDto<T>
{
public Type EntityType { get; set; }
public Expression<Func<T, DataInspection>> Expression { get; set; }
}
}
@@ -1,6 +1,8 @@
using System;
using IRaCIS.Core.Domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
@@ -14,12 +16,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common.Dto
public string Identification { get; set; }
}
public class TypeNameDto
public class ForeignKey
{
public string TypeName { get; set; }
public List<Type> Types { get; set; }
public string Text { get; set; }
}
}
@@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore.Common.Dto
{
public class ForeignKey
{
public string Text { get; set; }
}
}
@@ -1,82 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infra.EFCore
{
public static class EFSqlQuery
{
public static IEnumerable<T> SqlQuery<T>(this DatabaseFacade facade, string sql, params object[] parameters) where T : class, new()
{
DataTable dt = SqlQuery(facade, sql, parameters);
return dt.ToEnumerable<T>();
}
public static IEnumerable<T> ToEnumerable<T>(this DataTable dt) where T : class, new()
{
PropertyInfo[] propertyInfos = typeof(T).GetProperties();
T[] ts = new T[dt.Rows.Count];
int i = 0;
foreach (DataRow row in dt.Rows)
{
T t = new T();
foreach (PropertyInfo p in propertyInfos)
{
if (dt.Columns.IndexOf(p.Name) != -1 && row[p.Name] != DBNull.Value)
p.SetValue(t, row[p.Name], null);
}
ts[i] = t;
i++;
}
return ts;
}
public static DataTable SqlQuery(this DatabaseFacade facade, string sql, params object[] parameters)
{
DbCommand cmd = CreateCommand(facade, sql, out DbConnection conn, parameters);
DbDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
reader.Close();
conn.Close();
return dt;
}
private static DbCommand CreateCommand(DatabaseFacade facade, string sql, out DbConnection dbConn, params object[] parameters)
{
DbConnection conn = facade.GetDbConnection();
dbConn = conn;
conn.Open();
DbCommand cmd = conn.CreateCommand();
if (facade.IsRelational())
{
cmd.CommandText = sql;
CombineParams(ref cmd, parameters);
}
return cmd;
}
private static void CombineParams(ref DbCommand command, params object[] parameters)
{
if (parameters != null)
{
foreach (SqlParameter parameter in parameters)
{
if (!parameter.ParameterName.Contains("@"))
parameter.ParameterName = $"@{parameter.ParameterName}";
command.Parameters.Add(parameter);
}
}
}
}
}