mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 完善 所有参数化 object parms 可使用 IDictionary 类型传入;
This commit is contained in:
parent
dda7c8bc9c
commit
b5efb387bd
@ -99,6 +99,13 @@
|
||||
清空状态数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||
<summary>
|
||||
根据 lambda 条件删除数据
|
||||
</summary>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
|
@ -167,6 +167,12 @@ namespace FreeSql.Tests
|
||||
[Fact]
|
||||
public void Test02()
|
||||
{
|
||||
|
||||
var dicParamslist = g.sqlite.Select<SysModule>().Page(1, 10)
|
||||
.Where("id > @id and id > @id2 and id > @id3",
|
||||
new Dictionary<string, int> { ["id"] = 1, ["id2"] = 2, ["id3"] = 3 })
|
||||
.ToList();
|
||||
|
||||
var list111 = g.sqlite.Select<SysModule>()
|
||||
.Page(1, 10)
|
||||
.ToList(a => new { Id = a.Id })
|
||||
|
@ -1024,13 +1024,28 @@ namespace FreeSql.Internal
|
||||
var type = obj.GetType();
|
||||
if (type == ttype) return new[] { (T)Convert.ChangeType(obj, type) };
|
||||
var ret = new List<T>();
|
||||
var ps = type.GetPropertiesDictIgnoreCase().Values;
|
||||
foreach (var p in ps)
|
||||
var dic = obj as IDictionary;
|
||||
if (dic != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(paramPrefix) == false && sql.IndexOf($"{paramPrefix}{p.Name}", StringComparison.CurrentCultureIgnoreCase) == -1) continue;
|
||||
var pvalue = p.GetValue(obj, null);
|
||||
if (p.PropertyType == ttype) ret.Add((T)Convert.ChangeType(pvalue, ttype));
|
||||
else ret.Add(constructorParamter(p.Name, p.PropertyType, pvalue));
|
||||
foreach (var key in dic.Keys)
|
||||
{
|
||||
if (string.IsNullOrEmpty(paramPrefix) == false && sql.IndexOf($"{paramPrefix}{key}", StringComparison.CurrentCultureIgnoreCase) == -1) continue;
|
||||
var val = dic[key];
|
||||
var valType = val == null ? typeof(string) : val.GetType();
|
||||
if (valType == ttype) ret.Add((T)Convert.ChangeType(val, ttype));
|
||||
else ret.Add(constructorParamter(key.ToString(), valType, val));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var ps = type.GetPropertiesDictIgnoreCase().Values;
|
||||
foreach (var p in ps)
|
||||
{
|
||||
if (string.IsNullOrEmpty(paramPrefix) == false && sql.IndexOf($"{paramPrefix}{p.Name}", StringComparison.CurrentCultureIgnoreCase) == -1) continue;
|
||||
var pvalue = p.GetValue(obj, null);
|
||||
if (p.PropertyType == ttype) ret.Add((T)Convert.ChangeType(pvalue, ttype));
|
||||
else ret.Add(constructorParamter(p.Name, p.PropertyType, pvalue));
|
||||
}
|
||||
}
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user