移除 FreeSql.DbContext,成为独立项目

This commit is contained in:
28810
2019-04-01 10:48:39 +08:00
parent 3ca91b70a9
commit be5259dd68
32 changed files with 35 additions and 1862 deletions

View File

@ -304,6 +304,37 @@ namespace FreeSql.Extensions.EntityUtil {
func(item);
}
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object>>> _dicClearEntityPrimaryValueWithIdentity = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Action<object>>>();
/// <summary>
/// 清除实体的主键值将自增、Guid类型的主键值清除
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="orm"></param>
/// <param name="item"></param>
public static void ClearEntityPrimaryValueWithIdentity<TEntity>(this IFreeSql orm, TEntity item) {
var func = _dicClearEntityPrimaryValueWithIdentity.GetOrAdd(orm.Ado.DataType, dt => new ConcurrentDictionary<Type, Action<object>>()).GetOrAdd(typeof(TEntity), t => {
var _table = orm.CodeFirst.GetTableByEntity(t);
var identitys = _table.Primarys.Where(a => a.Attribute.IsIdentity);
var parm1 = Expression.Parameter(typeof(object));
var var1Parm = Expression.Variable(t);
var exps = new List<Expression>(new Expression[] {
Expression.Assign(var1Parm, Expression.TypeAs(parm1, t))
});
foreach (var pk in _table.Primarys) {
if (pk.Attribute.IsIdentity) {
exps.Add(
Expression.Assign(
Expression.MakeMemberAccess(var1Parm, _table.Properties[pk.CsName]),
Expression.Default(pk.CsType)
)
);
}
}
return Expression.Lambda<Action<object>>(Expression.Block(new[] { var1Parm }, exps), new[] { parm1 }).Compile();
});
func(item);
}
static ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Func<object, object, bool, string[]>>> _dicCompareEntityValueReturnColumns = new ConcurrentDictionary<DataType, ConcurrentDictionary<Type, Func<object, object, bool, string[]>>>();
/// <summary>
/// 对比两个实体值,返回相同/或不相同的列名