示例#1
0
        public void Or()
        {
            Script script    = new Script("Ids!=null || Name!=null or Names!=null");
            var    sqlParams = new SqlParameterCollection();

            sqlParams.TryAdd("Ids", new long[] { 1 });
            sqlParams.TryAdd("Name", "SmartSql");
            sqlParams.TryAdd("Names", new string[] { "SmartSql" });
            var isCondition = script.IsCondition(new RequestContext
            {
                Parameters = sqlParams
            });

            Assert.True(isCondition);
        }
示例#2
0
        public static int DeleteMany <TEntity, TPrimaryKey>(this IDbSession dbSession, IEnumerable <TPrimaryKey> ids)
        {
            var tableName  = EntityMetaDataCache <TEntity> .TableName;
            var pkCol      = EntityMetaDataCache <TEntity> .PrimaryKey;
            var sqlBuilder = new StringBuilder();

            sqlBuilder.AppendFormat("Delete From {0} Where {1} In (", tableName, pkCol.Name);
            var sqlParameters = new SqlParameterCollection();
            var index         = 0;

            foreach (var id in ids)
            {
                var idName       = $"{pkCol.Name}_{index}";
                var sqlParameter = new SqlParameter(idName, id, id.GetType())
                {
                    TypeHandler = TypeHandlerCache <TPrimaryKey, TPrimaryKey> .Handler
                };
                sqlParameters.TryAdd(sqlParameter);
                if (index > 0)
                {
                    sqlBuilder.Append(",");
                }

                AppendParameterName(sqlBuilder, dbSession.SmartSqlConfig.Database.DbProvider, idName);
                index++;
            }

            sqlBuilder.Append(")");
            return(dbSession.Execute(new RequestContext
            {
                RealSql = sqlBuilder.ToString(),
                Request = sqlParameters
            }));
        }
示例#3
0
        public void ArrayIndex()
        {
            SqlParameterCollection sqlParams = new SqlParameterCollection();

            sqlParams.TryAdd("Ids", new long[] { 1 });
            Script script      = new Script("Ids[0]==1");
            var    isCondition = script.IsCondition(new RequestContext
            {
                Parameters = sqlParams
            });

            Assert.True(isCondition);
        }
示例#4
0
        public void And()
        {
            Script script    = new Script("Ids!=null and Ids.length==1 and Ids[0]==1");
            var    sqlParams = new SqlParameterCollection();

            sqlParams.TryAdd("Ids", new long[] { 1 });
            var isCondition = script.IsCondition(new RequestContext
            {
                Parameters = sqlParams
            });

            Assert.True(isCondition);
        }
        public static int DeleteMany <TEntity, TPrimaryKey>(this IDbSession dbSession, IEnumerable <TPrimaryKey> ids)
        {
            var scope         = EntityMetaDataCache <TEntity> .Scope;
            var pkCol         = EntityMetaDataCache <TEntity> .PrimaryKey;
            var sqlParameters = new SqlParameterCollection();

            sqlParameters.TryAdd($"{pkCol.Name}s", ids);

            return(dbSession.Execute(new RequestContext
            {
                Scope = scope,
                SqlId = CUDStatementName.DELETE_MANY,
                Request = sqlParameters
            }));
        }
示例#6
0
        public void LessThen()
        {
            Script script    = new Script("Ids!=null and Ids.length<2 and Ids.length lt 2");
            var    sqlParams = new SqlParameterCollection();

            sqlParams.TryAdd("Ids", new long[] { 1 });

            var requestContext = new RequestContext
            {
                Request = sqlParams
            };

            requestContext.SetupParameters();
            var isCondition = script.IsCondition(requestContext);

            Assert.True(isCondition);
        }