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 Update时候 IgnoreColumns不起作用 #1892

Closed lhtuling closed 2 months ago

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

            var res = await DB.SqlServer.Update<object>()
                .AsType(Type.GetType($"Models." + TableName))
                .SetDto(ndata)
                .WhereDynamic(type.GetProperty("Id").GetValue(ndata))
                .IgnoreColumns(new[] { "Id" })
                .ExecuteUpdatedAsync();
            return JsonSerializer.Serialize(new { data = res, status = 0 }, options);
        }

没有效果,并没有忽略

2881099 commented 2 months ago

文档上写的

SetSource + IgnoreColumns/UpdateColumns 组合使用

SetDto 其实就是批量 Set

他们是两种操作模式。

lhtuling commented 2 months ago

已解决,文档看少了。。,感谢老板及时回复!