mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 修复 Aop.AuditValue 与 FreeSql.Repository 主键状态管理的冲突;
This commit is contained in:
parent
16bd3941c5
commit
baf6d768a4
@ -210,6 +210,7 @@ namespace FreeSql
|
|||||||
if (isThrow) throw new Exception($"不可添加,实体没有主键:{_db.Orm.GetEntityString(_entityType, data)}");
|
if (isThrow) throw new Exception($"不可添加,实体没有主键:{_db.Orm.GetEntityString(_entityType, data)}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
FreeSql.Internal.CommonProvider.InsertProvider<TEntity>.AuditDataValue(this, data, _db.Orm, _table);
|
||||||
var key = _db.Orm.GetEntityKeyString(_entityType, data, true);
|
var key = _db.Orm.GetEntityKeyString(_entityType, data, true);
|
||||||
if (string.IsNullOrEmpty(key))
|
if (string.IsNullOrEmpty(key))
|
||||||
{
|
{
|
||||||
@ -269,6 +270,7 @@ namespace FreeSql
|
|||||||
if (isThrow) throw new Exception($"不可更新,实体没有主键:{_db.Orm.GetEntityString(_entityType, data)}");
|
if (isThrow) throw new Exception($"不可更新,实体没有主键:{_db.Orm.GetEntityString(_entityType, data)}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
FreeSql.Internal.CommonProvider.UpdateProvider<TEntity>.AuditDataValue(this, data, _db.Orm, _table);
|
||||||
var key = _db.Orm.GetEntityKeyString(_entityType, data, false);
|
var key = _db.Orm.GetEntityKeyString(_entityType, data, false);
|
||||||
if (string.IsNullOrEmpty(key))
|
if (string.IsNullOrEmpty(key))
|
||||||
{
|
{
|
||||||
|
@ -199,5 +199,152 @@
|
|||||||
创建日期
|
创建日期
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:Zeus.Utility.Entity.EntityBase`1">
|
||||||
|
<summary>
|
||||||
|
实体类基类
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Zeus.Utility.Entity.EntityBase`1.#ctor">
|
||||||
|
<summary>
|
||||||
|
初始化一个<see cref="T:Zeus.Utility.Entity.EntityBase`1"/>类型的新实例
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.Utility.Entity.EntityBase`1.ID">
|
||||||
|
<summary>
|
||||||
|
获取或设置主键
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.Utility.Entity.EntityBase`1.CreatedAt">
|
||||||
|
<summary>
|
||||||
|
创建时间
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Zeus.Utility.Entity.EntityBase`1.Equals(System.Object)">
|
||||||
|
<summary>
|
||||||
|
判断两个实体是否是同一数据记录的实体
|
||||||
|
</summary>
|
||||||
|
<param name="obj">要比较的实体信息</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Zeus.Utility.Entity.EntityBase`1.IsKeyEqual(`0,`0)">
|
||||||
|
<summary>
|
||||||
|
实体Id是否相等
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Zeus.Utility.Entity.EntityBase`1.GetHashCode">
|
||||||
|
<summary>
|
||||||
|
用作特定类型的哈希函数
|
||||||
|
</summary>
|
||||||
|
<returns>
|
||||||
|
当前 <see cref="T:System.Object"/> 的哈希代码。<br/>
|
||||||
|
如果<c>Id</c>为<c>null</c>则返回0,
|
||||||
|
如果不为<c>null</c>则返回<c>Id</c>对应的哈希值
|
||||||
|
</returns>
|
||||||
|
</member>
|
||||||
|
<member name="T:Zeus.Utility.Entity.IEntity`1">
|
||||||
|
<summary>
|
||||||
|
数据模型接口
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.Utility.Entity.IEntity`1.ID">
|
||||||
|
<summary>
|
||||||
|
实体唯一标识,主键
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.Utility.Entity.IEntity`1.CreatedAt">
|
||||||
|
<summary>
|
||||||
|
创建时间
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="T:Zeus.Domain.Enum.IdentityType">
|
||||||
|
<summary>
|
||||||
|
登录类型
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="T:Zeus.SystemUser">
|
||||||
|
<summary>
|
||||||
|
用户表
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.DisplayName">
|
||||||
|
<summary>
|
||||||
|
显示名称
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.RealName">
|
||||||
|
<summary>
|
||||||
|
真实名称
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.Gender">
|
||||||
|
<summary>
|
||||||
|
性别
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.Birthday">
|
||||||
|
<summary>
|
||||||
|
生日
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.AvaterURL">
|
||||||
|
<summary>
|
||||||
|
头像URL地址
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.Remark">
|
||||||
|
<summary>
|
||||||
|
备注
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.IsEnabled">
|
||||||
|
<summary>
|
||||||
|
启用标志
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.IsDeleted">
|
||||||
|
<summary>
|
||||||
|
删除标志
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUser.SystemUserAuthentication_List">
|
||||||
|
<summary>
|
||||||
|
所属用户认证记录
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="T:Zeus.SystemUserAuthentication">
|
||||||
|
<summary>
|
||||||
|
用户认证表
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUserAuthentication.SystemUserID">
|
||||||
|
<summary>
|
||||||
|
用户表ID
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUserAuthentication.SystemUser">
|
||||||
|
<summary>
|
||||||
|
用户
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUserAuthentication.IdentityType">
|
||||||
|
<summary>
|
||||||
|
登录类型
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUserAuthentication.Identifier">
|
||||||
|
<summary>
|
||||||
|
登录标识
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUserAuthentication.Credential">
|
||||||
|
<summary>
|
||||||
|
登录凭证
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Zeus.SystemUserAuthentication.IsVerified">
|
||||||
|
<summary>
|
||||||
|
验证标志
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
84
FreeSql.Tests/FreeSql.Tests/Other/EntityBase.cs
Normal file
84
FreeSql.Tests/FreeSql.Tests/Other/EntityBase.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Zeus.Utility.Entity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 实体类基类
|
||||||
|
/// </summary>
|
||||||
|
public abstract class EntityBase<TKey> : IEntity<TKey> where TKey : IEquatable<TKey>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化一个<see cref="EntityBase{TKey}"/>类型的新实例
|
||||||
|
/// </summary>
|
||||||
|
protected EntityBase()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置主键
|
||||||
|
/// </summary>
|
||||||
|
[Key]
|
||||||
|
public virtual TKey ID { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
public virtual DateTime CreatedAt { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断两个实体是否是同一数据记录的实体
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">要比较的实体信息</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(obj is EntityBase<TKey> entity))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return IsKeyEqual(entity.ID, ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实体Id是否相等
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsKeyEqual(TKey id1, TKey id2)
|
||||||
|
{
|
||||||
|
if (id1 == null && id2 == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (id1 == null || id2 == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Equals(id1, id2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用作特定类型的哈希函数
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// 当前 <see cref="T:System.Object"/> 的哈希代码。<br/>
|
||||||
|
/// 如果<c>Id</c>为<c>null</c>则返回0,
|
||||||
|
/// 如果不为<c>null</c>则返回<c>Id</c>对应的哈希值
|
||||||
|
/// </returns>
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
if (ID == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ID.ToString().GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
FreeSql.Tests/FreeSql.Tests/Other/IEntity.cs
Normal file
21
FreeSql.Tests/FreeSql.Tests/Other/IEntity.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Zeus.Utility.Entity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 数据模型接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IEntity<out TKey>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 实体唯一标识,主键
|
||||||
|
/// </summary>
|
||||||
|
TKey ID { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
DateTime CreatedAt { get; set; }
|
||||||
|
}
|
||||||
|
}
|
16
FreeSql.Tests/FreeSql.Tests/Other/IdentityType.cs
Normal file
16
FreeSql.Tests/FreeSql.Tests/Other/IdentityType.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Zeus.Domain.Enum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 登录类型
|
||||||
|
/// </summary>
|
||||||
|
public enum IdentityType
|
||||||
|
{
|
||||||
|
Account,
|
||||||
|
Email,
|
||||||
|
Mobile
|
||||||
|
}
|
||||||
|
}
|
60
FreeSql.Tests/FreeSql.Tests/Other/SystemUser.cs
Normal file
60
FreeSql.Tests/FreeSql.Tests/Other/SystemUser.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using Zeus.Utility.Entity;
|
||||||
|
|
||||||
|
namespace Zeus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户表
|
||||||
|
/// </summary>
|
||||||
|
[Table(Name = "system_user")]
|
||||||
|
public partial class SystemUser : EntityBase<long>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 显示名称
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(20)", IsNullable = false, Unique = "UK_DisplayName")]
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 真实名称
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(20)")]
|
||||||
|
public string RealName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 性别
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(2)")]
|
||||||
|
public string Gender { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 生日
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "datetime")]
|
||||||
|
public DateTime? Birthday { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 头像URL地址
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(200)")]
|
||||||
|
public string AvaterURL { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(500)")]
|
||||||
|
public string Remark { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 启用标志
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "bit(1)", IsNullable = false)]
|
||||||
|
public bool IsEnabled { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 删除标志
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "bit(1)", IsNullable = false)]
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 所属用户认证记录
|
||||||
|
/// </summary>
|
||||||
|
[Navigate("SystemUserID")]
|
||||||
|
public ICollection<SystemUserAuthentication> SystemUserAuthentication_List { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using FreeSql.DataAnnotations;
|
||||||
|
using Zeus.Domain.Enum;
|
||||||
|
using Zeus.Utility.Entity;
|
||||||
|
|
||||||
|
namespace Zeus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户认证表
|
||||||
|
/// </summary>
|
||||||
|
[Table(Name = "system_user_authentication")]
|
||||||
|
public partial class SystemUserAuthentication : EntityBase<long>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户表ID
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "bigint(20)", IsNullable = false)]
|
||||||
|
public long SystemUserID { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 用户
|
||||||
|
/// </summary>
|
||||||
|
[Navigate("SystemUserID")]
|
||||||
|
public SystemUser SystemUser { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 登录类型
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(10)", MapType = typeof(string), IsNullable = false)]
|
||||||
|
public IdentityType IdentityType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 登录标识
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(50)", IsNullable = false, Unique = "UK_Identifier")]
|
||||||
|
public string Identifier { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 登录凭证
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "varchar(50)", IsNullable = false)]
|
||||||
|
public string Credential { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 验证标志
|
||||||
|
/// </summary>
|
||||||
|
[Column(DbType = "bit(1)", IsNullable = false)]
|
||||||
|
public bool IsVerified { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,10 @@ using System.Linq.Expressions;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Zeus;
|
||||||
|
using Zeus.Domain.Enum;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace FreeSql.Tests
|
namespace FreeSql.Tests
|
||||||
{
|
{
|
||||||
@ -345,9 +349,54 @@ namespace FreeSql.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int GetUNIX_TIMESTAMP() => 0;
|
public static int GetUNIX_TIMESTAMP() => 0;
|
||||||
|
|
||||||
|
private List<SystemUser> GetSystemUser()
|
||||||
|
{
|
||||||
|
SystemUser user = new SystemUser
|
||||||
|
{
|
||||||
|
DisplayName = "系统管理员",
|
||||||
|
RealName = "系统管理员",
|
||||||
|
Gender = "男",
|
||||||
|
Birthday = new DateTime(1984, 7, 1),
|
||||||
|
IsEnabled = true,
|
||||||
|
IsDeleted = false,
|
||||||
|
Remark = "禁止删除",
|
||||||
|
SystemUserAuthentication_List = new List<SystemUserAuthentication>()
|
||||||
|
};
|
||||||
|
user.SystemUserAuthentication_List.Add(new SystemUserAuthentication()
|
||||||
|
{
|
||||||
|
IdentityType = IdentityType.Account,
|
||||||
|
Identifier = "admin",
|
||||||
|
Credential = "HyrPNXuCBaqZU3QIJqP9eThOHpFfm9p+",
|
||||||
|
IsVerified = true
|
||||||
|
});
|
||||||
|
user.SystemUserAuthentication_List.Add(new SystemUserAuthentication()
|
||||||
|
{
|
||||||
|
IdentityType = IdentityType.Mobile,
|
||||||
|
Identifier = "13580592001",
|
||||||
|
Credential = "HyrPNXuCBaqZU3QIJqP9eThOHpFfm9p+",
|
||||||
|
IsVerified = true
|
||||||
|
});
|
||||||
|
var users = new List<SystemUser>
|
||||||
|
{
|
||||||
|
user
|
||||||
|
};
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Test1()
|
public void Test1()
|
||||||
{
|
{
|
||||||
|
//g.mysql.Aop.AuditValue += (s, e) =>
|
||||||
|
//{
|
||||||
|
// if (e.Column.CsType == typeof(long)
|
||||||
|
// && e.Property.GetCustomAttribute<KeyAttribute>(false) != null
|
||||||
|
// && e.Value?.ToString() == "0")
|
||||||
|
// e.Value = new Random().Next();
|
||||||
|
//};
|
||||||
|
//g.mysql.GetRepository<SystemUser>().Insert(GetSystemUser());
|
||||||
|
|
||||||
g.mysql.Aop.ParseExpression += new EventHandler<Aop.ParseExpressionEventArgs>((s, e) =>
|
g.mysql.Aop.ParseExpression += new EventHandler<Aop.ParseExpressionEventArgs>((s, e) =>
|
||||||
{
|
{
|
||||||
if (e.Expression.NodeType == ExpressionType.Call && (e.Expression as MethodCallExpression).Method.Name == "GetUNIX_TIMESTAMP")
|
if (e.Expression.NodeType == ExpressionType.Call && (e.Expression as MethodCallExpression).Method.Name == "GetUNIX_TIMESTAMP")
|
||||||
|
@ -2164,7 +2164,7 @@
|
|||||||
耗时(单位:毫秒)
|
耗时(单位:毫秒)
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:FreeSql.Aop.AuditValueEventArgs.AutoValueType">
|
<member name="P:FreeSql.Aop.AuditValueEventArgs.AuditValueType">
|
||||||
<summary>
|
<summary>
|
||||||
类型
|
类型
|
||||||
</summary>
|
</summary>
|
||||||
|
@ -273,18 +273,18 @@ namespace FreeSql.Aop
|
|||||||
|
|
||||||
public class AuditValueEventArgs : EventArgs
|
public class AuditValueEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public AuditValueEventArgs(AutoValueType autoValueType, ColumnInfo column, PropertyInfo property, object value)
|
public AuditValueEventArgs(AuditValueType autoValueType, ColumnInfo column, PropertyInfo property, object value)
|
||||||
{
|
{
|
||||||
this.AutoValueType = autoValueType;
|
this.AuditValueType = autoValueType;
|
||||||
this.Column = column;
|
this.Column = column;
|
||||||
this.Property = property;
|
this.Property = property;
|
||||||
this.Value = value;
|
this._value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 类型
|
/// 类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AutoValueType AutoValueType { get; }
|
public AuditValueType AuditValueType { get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 属性列的元数据
|
/// 属性列的元数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -308,5 +308,5 @@ namespace FreeSql.Aop
|
|||||||
private object _value;
|
private object _value;
|
||||||
public bool IsChanged { get; private set; }
|
public bool IsChanged { get; private set; }
|
||||||
}
|
}
|
||||||
public enum AutoValueType { Update, Insert }
|
public enum AuditValueType { Update, Insert }
|
||||||
}
|
}
|
@ -71,19 +71,56 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
public IInsert<T1> AppendData(T1 source)
|
public IInsert<T1> AppendData(T1 source)
|
||||||
{
|
{
|
||||||
if (source != null) _source.Add(source);
|
if (source != null)
|
||||||
|
{
|
||||||
|
AuditDataValue(this, source, _orm, _table);
|
||||||
|
_source.Add(source);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public IInsert<T1> AppendData(T1[] source)
|
public IInsert<T1> AppendData(T1[] source)
|
||||||
{
|
{
|
||||||
if (source != null) _source.AddRange(source);
|
if (source != null)
|
||||||
|
{
|
||||||
|
AuditDataValue(this, source, _orm, _table);
|
||||||
|
_source.AddRange(source);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public IInsert<T1> AppendData(IEnumerable<T1> source)
|
public IInsert<T1> AppendData(IEnumerable<T1> source)
|
||||||
{
|
{
|
||||||
if (source != null) _source.AddRange(source.Where(a => a != null));
|
if (source != null)
|
||||||
|
{
|
||||||
|
source = source.Where(a => a != null).ToList();
|
||||||
|
AuditDataValue(this, source, _orm, _table);
|
||||||
|
_source.AddRange(source);
|
||||||
|
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public static void AuditDataValue(object sender, IEnumerable<T1> data, IFreeSql orm, TableInfo table)
|
||||||
|
{
|
||||||
|
if (data?.Any() != true) return;
|
||||||
|
foreach (var d in data)
|
||||||
|
AuditDataValue(sender, d, orm, table);
|
||||||
|
}
|
||||||
|
public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table)
|
||||||
|
{
|
||||||
|
if (data == null) return;
|
||||||
|
foreach (var col in table.Columns.Values)
|
||||||
|
{
|
||||||
|
object val = col.GetMapValue(data);
|
||||||
|
if (col.Attribute.IsPrimary && col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
|
||||||
|
col.SetMapValue(data, val = FreeUtil.NewMongodbId());
|
||||||
|
if (orm.Aop.AuditValue != null)
|
||||||
|
{
|
||||||
|
var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Insert, col, table.Properties[col.CsName], val);
|
||||||
|
orm.Aop.AuditValue(sender, auditArgs);
|
||||||
|
if (auditArgs.IsChanged)
|
||||||
|
col.SetMapValue(data, val = auditArgs.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region 参数化数据限制,或values数量限制
|
#region 参数化数据限制,或values数量限制
|
||||||
protected List<T1>[] SplitSource(int valuesLimit, int parameterLimit)
|
protected List<T1>[] SplitSource(int valuesLimit, int parameterLimit)
|
||||||
@ -557,15 +594,6 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
object val = col.GetMapValue(d);
|
object val = col.GetMapValue(d);
|
||||||
if (col.Attribute.IsPrimary && col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
|
|
||||||
col.SetMapValue(d, val = FreeUtil.NewMongodbId());
|
|
||||||
if (_orm.Aop.AuditValue != null)
|
|
||||||
{
|
|
||||||
var auditArgs = new Aop.AuditValueEventArgs(Aop.AutoValueType.Insert, col, _table.Properties[col.CsName], val);
|
|
||||||
_orm.Aop.AuditValue(this, auditArgs);
|
|
||||||
if (auditArgs.IsChanged)
|
|
||||||
col.SetMapValue(d, val = auditArgs.Value);
|
|
||||||
}
|
|
||||||
if (_noneParameter)
|
if (_noneParameter)
|
||||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
|
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
|
||||||
else
|
else
|
||||||
|
@ -401,10 +401,42 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AuditDataValue(object sender, IEnumerable<T1> data, IFreeSql orm, TableInfo table)
|
||||||
|
{
|
||||||
|
if (data?.Any() != true) return;
|
||||||
|
if (orm.Aop.AuditValue == null) return;
|
||||||
|
foreach (var d in data)
|
||||||
|
{
|
||||||
|
if (d == null) continue;
|
||||||
|
foreach (var col in table.Columns.Values)
|
||||||
|
{
|
||||||
|
object val = col.GetMapValue(d);
|
||||||
|
var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Update, col, table.Properties[col.CsName], val);
|
||||||
|
orm.Aop.AuditValue(sender, auditArgs);
|
||||||
|
if (auditArgs.IsChanged)
|
||||||
|
col.SetMapValue(d, val = auditArgs.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table)
|
||||||
|
{
|
||||||
|
if (orm.Aop.AuditValue == null) return;
|
||||||
|
if (data == null) return;
|
||||||
|
foreach (var col in table.Columns.Values)
|
||||||
|
{
|
||||||
|
object val = col.GetMapValue(data);
|
||||||
|
var auditArgs = new Aop.AuditValueEventArgs(Aop.AuditValueType.Update, col, table.Properties[col.CsName], val);
|
||||||
|
orm.Aop.AuditValue(sender, auditArgs);
|
||||||
|
if (auditArgs.IsChanged)
|
||||||
|
col.SetMapValue(data, val = auditArgs.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IUpdate<T1> SetSource(T1 source) => this.SetSource(new[] { source });
|
public IUpdate<T1> SetSource(T1 source) => this.SetSource(new[] { source });
|
||||||
public IUpdate<T1> SetSource(IEnumerable<T1> source)
|
public IUpdate<T1> SetSource(IEnumerable<T1> source)
|
||||||
{
|
{
|
||||||
if (source == null || source.Any() == false) return this;
|
if (source == null || source.Any() == false) return this;
|
||||||
|
AuditDataValue(this, source, _orm, _table);
|
||||||
_source.AddRange(source.Where(a => a != null));
|
_source.AddRange(source.Where(a => a != null));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -606,13 +638,6 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (colidx > 0) sb.Append(", ");
|
if (colidx > 0) sb.Append(", ");
|
||||||
sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");
|
sb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");
|
||||||
var val = col.GetMapValue(_source.First());
|
var val = col.GetMapValue(_source.First());
|
||||||
if (_orm.Aop.AuditValue != null)
|
|
||||||
{
|
|
||||||
var auditArgs = new Aop.AuditValueEventArgs(Aop.AutoValueType.Update, col, _table.Properties[col.CsName], val);
|
|
||||||
_orm.Aop.AuditValue(this, auditArgs);
|
|
||||||
if (auditArgs.IsChanged)
|
|
||||||
col.SetMapValue(_source.First(), val = auditArgs.Value);
|
|
||||||
}
|
|
||||||
if (_noneParameter)
|
if (_noneParameter)
|
||||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, col.Attribute.MapType, val));
|
sb.Append(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, col.Attribute.MapType, val));
|
||||||
else
|
else
|
||||||
@ -652,13 +677,6 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
ToSqlWhen(cwsb, _table.Primarys, d);
|
ToSqlWhen(cwsb, _table.Primarys, d);
|
||||||
cwsb.Append(" THEN ");
|
cwsb.Append(" THEN ");
|
||||||
var val = col.GetMapValue(d);
|
var val = col.GetMapValue(d);
|
||||||
if (_orm.Aop.AuditValue != null)
|
|
||||||
{
|
|
||||||
var auditArgs = new Aop.AuditValueEventArgs(Aop.AutoValueType.Update, col, _table.Properties[col.CsName], val);
|
|
||||||
_orm.Aop.AuditValue(this, auditArgs);
|
|
||||||
if (auditArgs.IsChanged)
|
|
||||||
col.SetMapValue(_source.First(), val = auditArgs.Value);
|
|
||||||
}
|
|
||||||
if (_noneParameter)
|
if (_noneParameter)
|
||||||
cwsb.Append(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, col.Attribute.MapType, val));
|
cwsb.Append(_commonUtils.GetNoneParamaterSqlValue(_paramsSource, col.Attribute.MapType, val));
|
||||||
else
|
else
|
||||||
|
@ -57,22 +57,22 @@ namespace FreeSql.Internal.Model
|
|||||||
var objExp = Expression.Parameter(typeof(object), "obj");
|
var objExp = Expression.Parameter(typeof(object), "obj");
|
||||||
var valExp = Expression.Parameter(typeof(object), "val");
|
var valExp = Expression.Parameter(typeof(object), "val");
|
||||||
|
|
||||||
if (Attribute.MapType == CsType)
|
//if (Attribute.MapType == CsType)
|
||||||
return Expression.Lambda<Action<object, object>>(
|
// return Expression.Lambda<Action<object, object>>(
|
||||||
Expression.Assign(Expression.MakeMemberAccess(
|
// Expression.Assign(Expression.MakeMemberAccess(
|
||||||
Expression.TypeAs(objExp, col.Table.Type),
|
// Expression.TypeAs(objExp, col.Table.Type),
|
||||||
Table.Properties[col.CsName]
|
// Table.Properties[col.CsName]
|
||||||
), Expression.Convert(
|
// ), Expression.Convert(
|
||||||
valExp,
|
// valExp,
|
||||||
Attribute.MapType)), objExp, valExp).Compile();
|
// Attribute.MapType)), objExp, valExp).Compile();
|
||||||
|
|
||||||
return Expression.Lambda<Action<object, object>>(
|
return Expression.Lambda<Action<object, object>>(
|
||||||
Expression.Assign(Expression.MakeMemberAccess(
|
Expression.Assign(Expression.MakeMemberAccess(
|
||||||
Expression.TypeAs(objExp, col.Table.Type),
|
Expression.TypeAs(objExp, col.Table.Type),
|
||||||
Table.Properties[col.CsName]
|
Table.Properties[col.CsName]
|
||||||
), Expression.Convert(
|
), Expression.Convert(
|
||||||
Utils.GetDataReaderValueBlockExpression(Attribute.MapType, valExp),
|
Utils.GetDataReaderValueBlockExpression(CsType, valExp),
|
||||||
Attribute.MapType)), objExp, valExp).Compile();
|
CsType)), objExp, valExp).Compile();
|
||||||
});
|
});
|
||||||
func(obj, val);
|
func(obj, val);
|
||||||
}
|
}
|
||||||
|
@ -68,15 +68,6 @@ namespace FreeSql.Oracle.Curd
|
|||||||
|
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
object val = col.GetMapValue(d);
|
object val = col.GetMapValue(d);
|
||||||
if (col.Attribute.IsPrimary && col.Attribute.MapType.NullableTypeOrThis() == typeof(Guid) && (val == null || (Guid)val == Guid.Empty))
|
|
||||||
col.SetMapValue(d, val = FreeUtil.NewMongodbId());
|
|
||||||
if (_orm.Aop.AuditValue != null)
|
|
||||||
{
|
|
||||||
var auditArgs = new Aop.AuditValueEventArgs(Aop.AutoValueType.Insert, col, _table.Properties[col.CsName], val);
|
|
||||||
_orm.Aop.AuditValue(this, auditArgs);
|
|
||||||
if (auditArgs.IsChanged)
|
|
||||||
col.SetMapValue(d, val = auditArgs.Value);
|
|
||||||
}
|
|
||||||
if (_noneParameter)
|
if (_noneParameter)
|
||||||
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
|
sb.Append(_commonUtils.GetNoneParamaterSqlValue(specialParams, col.Attribute.MapType, val));
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user