Ejemplo n.º 1
0
        public static void CompareSql(DbContext db, DbOperateBase ope, string sql)
        {
            DbOperateBase operate = (DbOperateBase)ope;
            var           comands = new OperateCommandCollection(operate.Executor);

            comands.NextCommand();

            var generatesql = ope.GenerateSql();

            CompareSql(sql, generatesql);
        }
Ejemplo n.º 2
0
        public static void CompareSql(DbContext db, Expression exp, string sql)
        {
            var itemtype = exp.Type;

            if (itemtype.IsGenericType && typeof(IEnumerable).IsAssignableFrom(itemtype))
            {
                itemtype = itemtype.GetGenericArguments()[0];
            }
            var _Operate   = new DbQueryCollectionOperate(db, exp, itemtype);
            var expression = db.Configuration.Translator.Translate(_Operate);
            var comands    = new OperateCommandCollection(_Operate.Executor);

            comands.NextCommand();

            var generatesql = db.Database.Generator.Generate(_Operate, expression);

            CompareSql(sql, generatesql);
        }
Ejemplo n.º 3
0
        //根据操作集合生成执行命令集合对象。
        private OperateCommandCollection GenerateCommands(IEnumerable <DbOperateBase> operateCollection)
        {
            var operates = operateCollection.ToArray();
            var commands = new OperateCommandCollection(this);
            var database = Context.Database;

            int parametercount = database.Feature.MaxParameterCountForOperate;

            foreach (var operate in operates)
            {
                if (operate is IDbSplitObjectsOperate itemoperate)
                {
                    var current = commands.CheckParameterCount(parametercount);
                    parametercount = itemoperate.ItemParameterCount * itemoperate.Count;
                    if (operate is IConcurrencyCheckOperate concurrency && concurrency.NeedCheck &&
                        current.ConcurrencyExpectCount == 0 && !current.IsEmpty)
                    {
                        //如果当前操作需要参与并发检查,但是当前命令中已包含非并发检查操作,则移动到下一个命令中。
                        current = commands.NextCommand();
                    }
                    if (parametercount > current.ParameterCount)
                    {
                        commands.Register(itemoperate);
                    }
                    else
                    {
                        commands.Register(operate, parametercount);
                    }
                }
                else
                {
                    commands.Register(operate, parametercount);
                }
            }
            return(commands);
        }