|
@@ -193,6 +193,22 @@ namespace UniformMaterialManagementSystem.Utils
|
|
connection.Close();
|
|
connection.Close();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static async Task<IEnumerable<T>> QueryAll<T>(string path, Func<IQueryable<T>, IQueryable<T>>? includeFunc = null) where T : class
|
|
|
|
+ {
|
|
|
|
+ var optionsBuilderSource = new DbContextOptionsBuilder<SqliteContext>();
|
|
|
|
+ optionsBuilderSource.UseSqlite($"Data Source={path}");
|
|
|
|
+
|
|
|
|
+ await using var targetContext = new SqliteContext(optionsBuilderSource.Options);
|
|
|
|
+
|
|
|
|
+ var query = targetContext.Set<T>().AsQueryable();
|
|
|
|
+ if (includeFunc != null)
|
|
|
|
+ {
|
|
|
|
+ query = includeFunc(query);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return query.ToList();
|
|
|
|
+ }
|
|
|
|
+
|
|
private static void CreateExportFolder()
|
|
private static void CreateExportFolder()
|
|
{
|
|
{
|
|
if (!Directory.Exists(DataBasePath))
|
|
if (!Directory.Exists(DataBasePath))
|
|
@@ -262,7 +278,7 @@ namespace UniformMaterialManagementSystem.Utils
|
|
iv = pdb.GetBytes(16); // 128位IV
|
|
iv = pdb.GetBytes(16); // 128位IV
|
|
}
|
|
}
|
|
|
|
|
|
- public static (string sql, List<SqliteParameter> parameters) ExistsSql<T>(T entity, string tableName) where T : class?
|
|
|
|
|
|
+ private static (string sql, List<SqliteParameter> parameters) ExistsSql<T>(T entity, string tableName) where T : class?
|
|
{
|
|
{
|
|
var type = typeof(T);
|
|
var type = typeof(T);
|
|
var primaryKeyProps = GetPrimaryKeyProperties<T>().ToList();
|
|
var primaryKeyProps = GetPrimaryKeyProperties<T>().ToList();
|
|
@@ -286,7 +302,7 @@ namespace UniformMaterialManagementSystem.Utils
|
|
.Where(p => p.GetCustomAttributes(typeof(KeyAttribute), true).Any());
|
|
.Where(p => p.GetCustomAttributes(typeof(KeyAttribute), true).Any());
|
|
}
|
|
}
|
|
|
|
|
|
- public static (string sql, List<SqliteParameter> parameters) InsertSql<T>(T entity, string tableName) where T : class?
|
|
|
|
|
|
+ private static (string sql, List<SqliteParameter> parameters) InsertSql<T>(T entity, string tableName) where T : class?
|
|
{
|
|
{
|
|
var type = typeof(T);
|
|
var type = typeof(T);
|
|
var properties = type.GetProperties().Where(p => !IsNavigationProperty(p)).ToArray();
|
|
var properties = type.GetProperties().Where(p => !IsNavigationProperty(p)).ToArray();
|
|
@@ -300,7 +316,7 @@ namespace UniformMaterialManagementSystem.Utils
|
|
return (sql, parameters);
|
|
return (sql, parameters);
|
|
}
|
|
}
|
|
|
|
|
|
- public static (string sql, List<SqliteParameter> parameters) UpdateSql<T>(T entity, string tableName) where T : class?
|
|
|
|
|
|
+ private static (string sql, List<SqliteParameter> parameters) UpdateSql<T>(T entity, string tableName) where T : class?
|
|
{
|
|
{
|
|
var type = typeof(T);
|
|
var type = typeof(T);
|
|
var primaryKeyProps = GetPrimaryKeyProperties<T>().ToList();
|
|
var primaryKeyProps = GetPrimaryKeyProperties<T>().ToList();
|
|
@@ -315,7 +331,7 @@ namespace UniformMaterialManagementSystem.Utils
|
|
return (sql, parameters);
|
|
return (sql, parameters);
|
|
}
|
|
}
|
|
|
|
|
|
- public static (string sql, List<SqliteParameter> parameters) DeleteSql<T>(T entity, string tableName) where T : class?
|
|
|
|
|
|
+ private static (string sql, List<SqliteParameter> parameters) DeleteSql<T>(T entity, string tableName) where T : class?
|
|
{
|
|
{
|
|
var primaryKeyProps = GetPrimaryKeyProperties<T>();
|
|
var primaryKeyProps = GetPrimaryKeyProperties<T>();
|
|
var whereClause = string.Join(" AND ", primaryKeyProps.Select(p => $"{p.Name} = @{p.Name}"));
|
|
var whereClause = string.Join(" AND ", primaryKeyProps.Select(p => $"{p.Name} = @{p.Name}"));
|
|
@@ -326,7 +342,7 @@ namespace UniformMaterialManagementSystem.Utils
|
|
return (sql, parameters);
|
|
return (sql, parameters);
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<SqliteParameter> CreateParameters<T>(T entity, bool includeAllProperties = true) where T : class?
|
|
|
|
|
|
+ private static List<SqliteParameter> CreateParameters<T>(T entity, bool includeAllProperties = true) where T : class?
|
|
{
|
|
{
|
|
var parameters = new List<SqliteParameter>();
|
|
var parameters = new List<SqliteParameter>();
|
|
var properties = typeof(T).GetProperties().Where(p => !IsNavigationProperty(p));
|
|
var properties = typeof(T).GetProperties().Where(p => !IsNavigationProperty(p));
|