Files
XplorePlane/XP.Common/Database/Helpers/SqliteParameterHelper.cs

49 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XP.Common.Database.Helpers
{
/// <summary>
/// SQLite参数化查询辅助工具
/// </summary>
public static class SqliteParameterHelper
{
/// <summary>
/// 创建参数字典
/// </summary>
/// <param name="keyValues">参数名-值对(如 ("Id", 1), ("Name", "Test")</param>
/// <returns>参数字典</returns>
public static Dictionary<string, object> CreateParameters(params (string Key, object Value)[] keyValues)
{
var parameters = new Dictionary<string, object>();
foreach (var (key, value) in keyValues)
{
parameters.Add(key, value);
}
return parameters;
}
/// <summary>
/// 合并参数字典
/// </summary>
public static Dictionary<string, object> MergeParameters(params Dictionary<string, object>[] paramLists)
{
var merged = new Dictionary<string, object>();
foreach (var paramList in paramLists)
{
foreach (var (key, value) in paramList)
{
if (!merged.ContainsKey(key))
{
merged.Add(key, value);
}
}
}
return merged;
}
}
}