mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
## v0.4.13
- 优化 MySql 日期类型精确至毫秒; - 增加 Distinct 查询前去重数据;
This commit is contained in:
@ -182,9 +182,9 @@ namespace FreeSql.Extensions.EntityUtil {
|
||||
/// <summary>
|
||||
/// 使用新实体的值,复盖旧实体的值
|
||||
/// </summary>
|
||||
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, object>>> _dicCopyNewValueToEntity = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, object>>>();
|
||||
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, object>>> _dicMapEntityValue = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, object>>>();
|
||||
public static void MapEntityValue<TEntity>(this IFreeSql orm, TEntity from, TEntity to) {
|
||||
var func = _dicCopyNewValueToEntity.GetOrAdd(orm.Ado.DataType, dt => new ConcurrentDictionary<Type, Action<object, object>>()).GetOrAdd(typeof(TEntity), t => {
|
||||
var func = _dicMapEntityValue.GetOrAdd(orm.Ado.DataType, dt => new ConcurrentDictionary<Type, Action<object, object>>()).GetOrAdd(typeof(TEntity), t => {
|
||||
var _table = orm.CodeFirst.GetTableByEntity(t);
|
||||
var parm1 = Expression.Parameter(typeof(object));
|
||||
var parm2 = Expression.Parameter(typeof(object));
|
||||
@ -216,6 +216,35 @@ namespace FreeSql.Extensions.EntityUtil {
|
||||
func(from, to);
|
||||
}
|
||||
|
||||
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, object>>> _dicMapEntityKeyValue = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, object>>>();
|
||||
/// <summary>
|
||||
/// 使用新实体的主键值,复盖旧实体的主键值
|
||||
/// </summary>
|
||||
public static void MapEntityKeyValue<TEntity>(this IFreeSql orm, TEntity from, TEntity to) {
|
||||
var func = _dicMapEntityKeyValue.GetOrAdd(orm.Ado.DataType, dt => new ConcurrentDictionary<Type, Action<object, object>>()).GetOrAdd(typeof(TEntity), t => {
|
||||
var _table = orm.CodeFirst.GetTableByEntity(t);
|
||||
var pks = _table.Primarys;
|
||||
var parm1 = Expression.Parameter(typeof(object));
|
||||
var parm2 = Expression.Parameter(typeof(object));
|
||||
var var1Parm = Expression.Variable(t);
|
||||
var var2Parm = Expression.Variable(t);
|
||||
var exps = new List<Expression>(new Expression[] {
|
||||
Expression.Assign(var1Parm, Expression.TypeAs(parm1, t)),
|
||||
Expression.Assign(var2Parm, Expression.TypeAs(parm2, t))
|
||||
});
|
||||
foreach (var pk in pks) {
|
||||
exps.Add(
|
||||
Expression.Assign(
|
||||
Expression.MakeMemberAccess(var2Parm, _table.Properties[pk.CsName]),
|
||||
Expression.MakeMemberAccess(var1Parm, _table.Properties[pk.CsName])
|
||||
)
|
||||
);
|
||||
}
|
||||
return Expression.Lambda<Action<object, object>>(Expression.Block(new[] { var1Parm, var2Parm }, exps), new[] { parm1, parm2 }).Compile();
|
||||
});
|
||||
func(from, to);
|
||||
}
|
||||
|
||||
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, long>>> _dicSetEntityIdentityValueWithPrimary = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object, long>>>();
|
||||
/// <summary>
|
||||
/// 设置实体中主键内的自增字段值(若存在)
|
||||
|
Reference in New Issue
Block a user