dotnetcore / FreeSql

🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, DuckDB orm, TDengine orm, QuestDB orm, MsAccess orm.
https://freesql.net
MIT License
4.13k stars 859 forks source link

弱类型 crud Insert时候 AppendData如果是object类型,会报错 #1891

Closed lhtuling closed 2 months ago

lhtuling commented 2 months ago
        public async static Task<object> Insert(object data)
        {
            var type = Type.GetType($"Models." + TableName);
            var jsonData = JsonSerializer.Serialize(data);
            object? ndata = JsonSerializer.Deserialize(jsonData, type);

            var res =await DB.SqlServer.Insert<object>()
                .AsType(type)
                .AppendData(ndata)  // 这里直接给data的话就会报错

                .ExecuteAffrowsAsync();
            return JsonSerializer.Serialize(new { data = res, status = 0 }, options);
        }
2881099 commented 2 months ago

转一次试试,Convert.Change

lhtuling commented 2 months ago

凑合先用了,感谢老板及时回复!