/// <summary>
 /// Get an expression that represents the update operation for the specified instance.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="instance">The instance.</param>
 /// <param name="updateCheck">The update check.</param>
 /// <param name="selector">The selector.</param>
 /// <param name="indeedColumns">The indeed columns.</param>
 /// <param name="else">The @else.</param>
 /// <returns></returns>
 public abstract Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, ColumnIndeedExpression indeedColumns, Expression @else);
 /// <summary>
 /// Get an expression that represents the insert operation for the specified instance.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="instance">The instance to insert.</param>
 /// <param name="selector">A lambda expression that computes a return value from the operation.</param>
 /// <param name="indeedColumns">指定需要插入的列.</param>
 /// <returns></returns>
 public abstract Expression GetInsertExpression(MappingEntity entity, Expression instance, LambdaExpression selector, ColumnIndeedExpression indeedColumns);
 private Expression BindUpdate(IEntityTable upd, Expression instance, LambdaExpression updateCheck, LambdaExpression resultSelector, ColumnIndeedExpression columnsToBeHandled)
 {
     MappingEntity entity = this.mapper.Mapping.GetEntity(instance.Type, upd.TableId);
     return this.Visit(this.mapper.GetUpdateExpression(entity, instance, updateCheck, resultSelector, columnsToBeHandled, null));
 }
        private Expression BindInsert(IEntityTable upd, Expression instance, LambdaExpression selector, ColumnIndeedExpression columnsToBeHandled)
        {
            MappingEntity entity = this.mapper.Mapping.GetEntity(instance.Type, upd.TableId);

            return this.Visit(this.mapper.GetInsertExpression(entity, instance, selector, columnsToBeHandled));
        }
        public override Expression GetInsertExpression(MappingEntity entity, Expression instance, LambdaExpression selector, ColumnIndeedExpression indeedColumns)
        {
            var tableAlias = new TableAlias();
            var table = new TableExpression(tableAlias, entity, this.mapping.GetTableName(entity));
            IEnumerable<ColumnAssignment> assignments = null;

            if (indeedColumns != null)
            {                //TODO :2010 -7-17 更新---> 解决 过滤指定了不参与插入或者更新的列字段
                assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => !this.mapping.IsIdentity(e, m) && indeedColumns.FieldsToBeUpdated.ColumnsToBeHandled.Contains(m.Name) && this.mapping.IsUpdatable(e, m));
            }
            else                //TODO :2010 -7-17 更新---> 解决 过滤指定了不参与插入或者更新的列字段
                assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => !this.mapping.IsIdentity(e, m) && this.mapping.IsUpdatable(e, m));


            if (selector != null)
            {
                return new BlockCommand(
                    new InsertCommand(table, assignments),
                    this.GetInsertResult(entity, instance, selector, null)
                    );
            }

            return new InsertCommand(table, assignments);
        }
        /// <summary>
        /// Get an expression that represents the update operation for the specified instance.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="instance">The instance.</param>
        /// <param name="updateCheck">The update check.</param>
        /// <param name="selector">The selector.</param>
        /// <param name="indeedColumns">The indeed columns.</param>
        /// <param name="else">The @else.</param>
        /// <returns></returns>
        public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, ColumnIndeedExpression indeedColumns, Expression @else)
        {
            var tableAlias = new TableAlias();
            var table = new TableExpression(tableAlias, entity, this.mapping.GetTableName(entity));
            Expression where = null;

            if (updateCheck != null)
            {
                Expression typeProjector = this.GetEntityExpression(table, entity);
                Expression pred = DbExpressionReplacer.Replace(updateCheck.Body, updateCheck.Parameters[0], typeProjector);
                where = pred;// 
                //TODO:解决了Update多个条件的问题2010-6-22 21:46
            }
            else
                where = this.GetIdentityCheck(table, entity, instance);
            IEnumerable<ColumnAssignment> assignments = null;// || indeedColumns.FieldsToBeUpdated.ColumnsToBeHandled.Count == 0
            if (indeedColumns == null || indeedColumns.FieldsToBeUpdated == null)
            {
                //TODO: 2010-7-4 解决 更新自动增长列的问题
                //TODO :2010 -7-17 更新---> 解决 过滤指定了不参与插入或者更新的列字段
                assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => !this.mapping.IsPrimaryKey(e, m) && !this.mapping.IsIdentity(e, m) && this.mapping.IsUpdatable(e, m));
            }
            else
            {
                //TODO:如果指定需要更新的字段列表有误..抛出异常   
                {
                    assignments = this.GetColumnAssignments(table, instance, entity, (e, m) => !this.mapping.IsPrimaryKey(e, m) && indeedColumns.FieldsToBeUpdated.ColumnsToBeHandled.Contains(m.Name) && !this.mapping.IsIdentity(e, m) && this.mapping.IsUpdatable(e, m));
                }


            }
            Expression update = new UpdateCommand(table, where, assignments);

            if (selector != null)
            {
                return new BlockCommand(
                    update,
                    new IFCommand(
                        this.translator.Linguist.Language.GetRowsAffectedExpression(update).GreaterThan(Expression.Constant(0)),
                        this.GetUpdateResult(entity, instance, selector),
                        @else
                        )
                    );
            }
            else if (@else != null)
            {
                return new BlockCommand(
                    update,
                    new IFCommand(
                        this.translator.Linguist.Language.GetRowsAffectedExpression(update).LessThanOrEqual(Expression.Constant(0)),
                        @else,
                        null
                        )
                    );
            }
            else
            {
                return update;
            }
        }