From e1f91ef361ca4a6eac7f217bd4a474047597e4e3 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Sat, 9 Mar 2024 10:18:26 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20DbSet/Repository=20Att?= =?UTF-8?q?ach=20=E4=B8=8E=20CanUpdate=20AuditValue=20=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98=EF=BC=9B#1746?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Examples/base_entity/Program.cs | 45 +++++++++++++++++++++++++++- Examples/base_entity/base_entity.xml | 15 ++++++++++ FreeSql.DbContext/DbSet/DbSet.cs | 1 + 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index f2cf67fc..4e33ff84 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -9,6 +9,7 @@ using FreeSql.Internal.Model; using FreeSql.Odbc.Default; using MessagePack; using Microsoft.Data.SqlClient; +using MySqlConnector; using NetTopologySuite.Geometries; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -571,7 +572,7 @@ namespace base_entity //.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true") - //.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true") + .UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true") //.UseAdoConnectionPool(false) //.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2") ////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2") @@ -611,6 +612,18 @@ namespace base_entity BaseEntity.Initialization(fsql, () => _asyncUow.Value); #endregion + fsql.Aop.AuditValue += (_, e) => + { + + }; + + var tt1 = new ProjectItem { ID = 1, MaxQuantity = 0, Code = null, Name = null }; + var tt2 = new ProjectItem { ID = 1, MaxQuantity = 100, Code = null, Name = null }; + var repot2 = fsql.GetRepository(); + + repot2.Attach(tt1); + var nt1 = repot2.Update(tt2); + var fsql2 = fsql; // 动态构建实体类型,树形结构,引用自身类型 var areaBuilder = fsql2.CodeFirst.DynamicEntity("Area", new TableAttribute { Name = "dy_area" }); @@ -3192,4 +3205,34 @@ public class VM_District_Parent : BaseDistrict [Navigate(nameof(ParentCode))] public VM_District_Parent Parent { get; set; } +} + +[JsonObject(MemberSerialization.OptIn), Table(DisableSyncStructure = true)] +public partial class ProjectItem +{ + [JsonProperty, Column(DbType = "bigint", IsPrimary = true, IsIdentity = true)] + public long ID { get; set; } + + + /// + /// 编码 + /// + [JsonProperty, Column(StringLength = 100, IsNullable = false)] + public string Code { get; set; } + + + /// + /// 实际最大用量 + /// + [JsonProperty, Column(DbType = "decimal(14,4)")] + public decimal MaxQuantity { get; set; } = 0.0000M; + + /// + /// 名称 + /// + [JsonProperty, Column(StringLength = 50, IsNullable = false)] + public string Name { get; set; } + + + } \ No newline at end of file diff --git a/Examples/base_entity/base_entity.xml b/Examples/base_entity/base_entity.xml index 0c30a069..73179bc3 100644 --- a/Examples/base_entity/base_entity.xml +++ b/Examples/base_entity/base_entity.xml @@ -316,6 +316,21 @@ 这个不行 + + + 编码 + + + + + 实际最大用量 + + + + + 名称 + + 角色表 diff --git a/FreeSql.DbContext/DbSet/DbSet.cs b/FreeSql.DbContext/DbSet/DbSet.cs index ae8db47b..e5548c7c 100644 --- a/FreeSql.DbContext/DbSet/DbSet.cs +++ b/FreeSql.DbContext/DbSet/DbSet.cs @@ -239,6 +239,7 @@ namespace FreeSql if (_table.Primarys.Any() == false) throw new Exception(DbContextStrings.CannotAttach_EntityHasNo_PrimaryKey(_db.OrmOriginal.GetEntityString(_entityType, data.First()))); foreach (var item in data) { + FreeSql.Internal.CommonProvider.UpdateProvider.AuditDataValue(this, item, _db.OrmOriginal, _table, null); //与 CanUpdate 同步 var key = _db.OrmOriginal.GetEntityKeyString(_entityType, item, false); if (string.IsNullOrEmpty(key)) throw new Exception(DbContextStrings.CannotAttach_PrimaryKey_NotSet(_db.OrmOriginal.GetEntityString(_entityType, item)));