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

查詢時的映射沒有優先採用資料庫資料 #1172

Closed Yumitoya8569 closed 11 months ago

Yumitoya8569 commented 1 year ago

環境

.Net 7 Oracle 11g SqlSugarCore 5.1.4.89

情境

我們有以下實體:

  public class TableA
  {
      [SugarColumn(IsPrimaryKey = true)]
      public string id { get; set; } = string.Empty;

      public string name { get; set; } = string.Empty;

      public DateTime? create_utc { get; set; } = DateTime.UtcNow;
  }
相應的資料庫資料: id name create_utc
a aa null

我們使用查詢:

 _db.Queryable<TableA>().ToOffsetPageAsync(1, 20)
會得到結果: id name create_utc
a aa 2023-07-11 14:26:26

問題

我不確定這個情況是基於設計還是bug
不過直覺上來講應該優先尊重資料庫的null值而非實體上的默認值

DotNetNext commented 1 year ago

目前设计数据库没有值就不绑定,这样能性能最大化

DotNetNext commented 1 year ago

[SugarColumn(InsertServerTime =true, IsOnlyIgnoreUpdate =true)] public DateTime CreateTime { get; set; }

你看看改成这样能不能解决你插入默认值问题

Yumitoya8569 commented 1 year ago

已把資料庫欄位改成not null來解決 不過這案例依然較超乎預期 建議再評估一下 謝謝

DotNetNext commented 1 year ago

好的我这边后面加个开关支持配置一下

DotNetNext commented 11 months ago

已加入到计划,后面版本会支持到moressting配置