private static Expression GetUpdateExpressionByCalculator(LambdaExpression lambda, LambdaExpression predicate) { var initExp = lambda.Body as MemberInitExpression; var newExp = initExp.NewExpression; var entityType = newExp.Type; var metadata = EntityMetadataUnity.GetEntityMetadata(entityType); var table = new TableExpression(new TableAlias(), metadata.TableName, metadata.EntityType); Expression where = null; var row = GetTypeProjection(table, metadata, false); if (predicate != null) { where = DbExpressionReplacer.Replace(predicate.Body, predicate.Parameters[0], row); } var list = new List <MemberAssignment>(); foreach (MemberAssignment ass in initExp.Bindings) { list.Add(Expression.Bind(ass.Member, DbExpressionReplacer.Replace(ass.Expression, lambda.Parameters[0], row))); } return(new UpdateCommandExpression(table, where, GetUpdateArguments(table, list))); }
private static Expression GetUpdateExpressionByEntity(ConstantExpression constant, LambdaExpression predicate) { var entity = constant.Value as IEntity; var metadata = EntityMetadataUnity.GetEntityMetadata(entity.EntityType); var table = new TableExpression(new TableAlias(), metadata.TableName, metadata.EntityType); Expression where = null; if (predicate != null) { var row = GetTypeProjection(table, metadata, false); where = DbExpressionReplacer.Replace(predicate.Body, predicate.Parameters[0], row); } return(new UpdateCommandExpression(table, where, GetUpdateArguments(table, entity))); }
internal static Expression GetLogicalDeleteExpression(EntityMetadata metadata, LambdaExpression predicate) { var table = new TableExpression(new TableAlias(), metadata.TableName, metadata.EntityType); Expression where = null; var delflag = (ColumnExpression)GetMemberExpression(table, metadata.DeleteProperty); var assignments = new List <ColumnAssignment> { new ColumnAssignment(delflag, Expression.Constant(true)) }; if (predicate != null) { var row = GetTypeProjection(table, metadata, false); where = DbExpressionReplacer.Replace(predicate.Body, predicate.Parameters[0], row); } return(new UpdateCommandExpression(table, where, assignments)); }
internal static Expression GetDeleteExpression(EntityMetadata metadata, LambdaExpression predicate, bool replace) { var table = new TableExpression(new TableAlias(), metadata.TableName, metadata.EntityType); Expression where = null; if (predicate != null) { if (replace) { var row = GetTypeProjection(table, metadata, false); where = DbExpressionReplacer.Replace(predicate.Body, predicate.Parameters[0], row); } else { where = predicate.Body; } } return(new DeleteCommandExpression(table, where)); }
private static Expression GetUpdateExpressionByCalculator(TranslateContext transContext, LambdaExpression lambda, LambdaExpression predicate, bool isAsync) { var initExp = lambda.Body as MemberInitExpression; var newExp = initExp.NewExpression; var entityType = newExp.Type; var metadata = EntityMetadataUnity.GetEntityMetadata(entityType); var table = new TableExpression(new TableAlias(), metadata.TableName, metadata.EntityType); Expression where = null; var row = GetTypeProjection(transContext, table, metadata); if (predicate != null) { where = DbExpressionReplacer.Replace(predicate.Body, predicate.Parameters[0], row); } var bindings = initExp.Bindings.Cast <MemberAssignment>().Select(m => Expression.Bind(m.Member, DbExpressionReplacer.Replace(m.Expression, lambda.Parameters[0], row))); return(new UpdateCommandExpression(table, where, GetUpdateArguments(transContext, table, bindings), isAsync)); }