DotNetNext / SqlSugar

.Net aot ORM Fastest ORM Simple Easy VB.NET Sqlite orm Oracle ORM Mysql Orm 虚谷数据库 postgresql ORm SqlServer oRm 达梦 ORM 人大金仓 ORM 神通ORM C# ORM , C# ORM .NET ORM NET5 ORM .NET6 ORM ClickHouse orm QuestDb ,TDengine ORM,OceanBase orm,GaussDB orm ,Tidb orm Object/Relational Mapping
https://www.donet5.com/Home/Doc
MIT License
5.19k stars 1.32k forks source link

Updateable一起使用 WhereColumns和UpdateColumns好像有错误 #1201

Closed Zero-Xiong closed 9 months ago

Zero-Xiong commented 9 months ago

使用版本:

SqlSugarCore (Version="5.1.4.110" ) .NET 7

使用例子: result = await db.Updateable(records) .WhereColumns(c => new { c.c1, c.c2, c.c3, c.c4 }) .UpdateColumns(u => new { u.column_to_be_updated }) .ExecuteCommandAsync();

错误信息:

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'T' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '', line 1, position 1.

at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at SqlSugar.SerializeService.DeserializeObject[T](String value) at SqlSugar.ContextMethods.DeserializeObject[T](String value) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at SqlSugar.SqlSugarProvider.Updateable[T](Object updateDynamicObject) at SqlSugar.SqlSugarScopeProvider.Updateable[T](Object updateDynamicObject)

Zero-Xiong commented 9 months ago

https://www.donet5.com/ask/9/23119

DotNetNext commented 9 months ago

未重现你的问题

DotNetNext commented 9 months ago

下面是完整的测试用例,你可以新建库进行测试

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace OrmTest
{
    internal class Unitdfafaaa
    {
        public static void Init() 
        {
            var db = NewUnitTest.Db;
            db.CodeFirst.InitTables<Invoice>();
            var result =   db.Updateable<Invoice>(new Invoice() { })

                                     .WhereColumns(c => new { c.comp_code, c.adi_order, c.invoice_no, c.cust_po_no })

                                     .UpdateColumns(u => new { u.customer_original_po })

                                     .ExecuteCommandAsync().GetAwaiter().GetResult();
        }
        [SqlSugar.SugarTable("inv_master")]

        public class Invoice

        {

            [SqlSugar.SugarColumn(IsIdentity = true)]

            public long id { get; set; }

            public string comp_code { get; set; } = "a";

            public string adi_order { get; set; } = "a";

            public string invoice_no { get; set; } = "a";

            public string cust_po_no { get; set; } = "a";

            public string customer_original_po { get; set; } = "a";

        }
    }
}