mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
Merge pull request #1403 from hyzx86/ExpandoObject
参数化增加 ExpandoObject支持
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -45,6 +46,30 @@ namespace FreeSql.Tests.Internal
|
||||
Assert.Equal("test", ps2[0].Value);
|
||||
Assert.Equal("p", ps2[0].ParameterName);
|
||||
Assert.Equal(typeof(SqlParameter), ps2[0].GetType());
|
||||
|
||||
|
||||
//测试匿名对象支持
|
||||
dynamic expObj = new ExpandoObject();
|
||||
expObj.p = "test";
|
||||
|
||||
Func<string, Type, object, DbParameter> constructorParamter = (name, type, value) =>
|
||||
{
|
||||
if (value?.Equals(DateTime.MinValue) == true) value = new DateTime(1970, 1, 1);
|
||||
var ret = new SqlParameter { ParameterName = $"@{name}", Value = value };
|
||||
return ret;
|
||||
};
|
||||
|
||||
var ps3 = FreeSql.Internal.Utils.
|
||||
GetDbParamtersByObject<DbParameter>("select @p",
|
||||
expObj,
|
||||
"@",
|
||||
constructorParamter);
|
||||
Assert.Single(ps3);
|
||||
Assert.Equal("test", ps3[0].Value);
|
||||
Assert.Equal("p", ps3[0].ParameterName);
|
||||
Assert.Equal(typeof(SqlParameter), ps3[0].GetType());
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -52,7 +77,7 @@ namespace FreeSql.Tests.Internal
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
string sql1 = "", sql2 = "", sql3 = "";
|
||||
|
||||
|
||||
sql2 = FreeSql.Internal.Utils.ReplaceSqlConstString(sql1 = @"UPDATE ""as_table_log_202201"" SET ""msg"" = 'msg01', ""createtime"" = '2022-01-01 13:00:11'
|
||||
WHERE (""id"" = '6252a2e6-5df3-bb10-00c1-bda60c4053fe')", dict);
|
||||
Assert.Equal(3, dict.Count);
|
||||
|
Reference in New Issue
Block a user