コード例 #1
0
ファイル: GenerateContext.cs プロジェクト: liuyuliuyu520/Mego
        /// <summary>
        /// 创建语句生成上下文。
        /// </summary>
        /// <param name="operate">操作对象。</param>
        /// <param name="generator">值生成对象。</param>
        public GenerateContext(DbOperateBase operate, SqlGeneratorBase generator)
        {
            var operateContext = operate.Executor;
            var dataContext    = operateContext.Context;

            Generator       = generator;
            _FragmentWriter = generator.FragmentWriter;
            var configure = dataContext.Configuration;

            Metadata    = configure.Metadata;
            _Translator = configure.Translator;
            Feature     = dataContext.Database.Feature;
            switch (operate.Type)
            {
            case EOperateType.InsertObjects:
            case EOperateType.InsertPropertys:
                Data = new GenerateDataForInsert(this, operate as DbObjectsOperateBase);
                break;

            case EOperateType.UpdateObjects:
            case EOperateType.UpdatePropertys:
                Data = new GenerateDataForUpdate(this, operate as DbObjectsOperateBase);
                break;

            case EOperateType.DeleteObjects:
                Data = new GenerateDataForDelete(this, operate as DbObjectsOperateBase);
                break;

            case EOperateType.AddRelation:
            case EOperateType.RemoveRelation:
                Data = new GenerateDataForRelation(this, operate as DbRelationOperateBase);
                break;

            case EOperateType.InsertStatement:
            case EOperateType.UpdateStatement:
            case EOperateType.DeleteStatement:
                Data = new GenerateDataForStatement(this, operate as DbStatementOperateBase);
                break;

            default:
                Data = new GenerateData(this, operate);
                break;
            }
        }
コード例 #2
0
        private SqlFragment GenerateForInsertIdentityMultipleRepeat(GenerateContext context, CommitIdentityUnit mainunit, ColumnMetadata rowindex,
                                                                    TemporaryTableFragment temporaryTable, RowIndexFragment rowindexfragment, GenerateDataForInsert data, out TableFragment whileTarget)
        {
            var repeatfragment = new RepeatBlockFragment(context, data.Items);
            var block          = repeatfragment.Block;
            var whileInsert    = context.Insert(temporaryTable, mainunit.Table,
                                                mainunit.Members.Where(a => a.ValueType != ECommitValueType.Database).Select(a => a.Metadata));
            var whileSelect = (QueryBaseFragment)whileInsert.Query;

            whileSelect.Where = context.Equal(temporaryTable.GetMember(rowindex), new RowIndexFragment(context));
            block.Add(whileInsert);
            var whileUpdate = new UpdateFragment(context, temporaryTable);
            var getidentity = whileUpdate.CreateExpression(
                context.Translate(Expression.Call(null, SupportMembers.DbFunctions.GetIdentity)));

            whileUpdate.SetValue(mainunit.Identity.Metadata, getidentity);
            whileUpdate.Where = context.Equal(temporaryTable.GetMember(rowindex), new RowIndexFragment(context));
            block.Add(whileUpdate);
            whileTarget = (TableFragment)whileInsert.Target;
            return(repeatfragment);
        }