コード例 #1
0
ファイル: QueryUtility.cs プロジェクト: xiawei666/fireasy2
        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)));
        }
コード例 #2
0
ファイル: QueryUtility.cs プロジェクト: xiawei666/fireasy2
        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)));
        }
コード例 #3
0
ファイル: QueryUtility.cs プロジェクト: xiawei666/fireasy2
        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));
        }
コード例 #4
0
ファイル: QueryUtility.cs プロジェクト: xiawei666/fireasy2
        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));
        }
コード例 #5
0
        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));
        }