当前位置: 首页>>代码示例>>C#>>正文


C# ISqlExpression类代码示例

本文整理汇总了C#中ISqlExpression的典型用法代码示例。如果您正苦于以下问题:C# ISqlExpression类的具体用法?C# ISqlExpression怎么用?C# ISqlExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ISqlExpression类属于命名空间,在下文中一共展示了ISqlExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildFunction

        protected override void BuildFunction(StringBuilder sb, SqlFunction func)
        {
            func = ConvertFunctionParameters(func);

            switch (func.Name)
            {
                case "CASE"     : func = ConvertCase(func.SystemType, func.Parameters, 0); break;
                case "Coalesce" :

                    if (func.Parameters.Length > 2)
                    {
                        var parms = new ISqlExpression[func.Parameters.Length - 1];

                        Array.Copy(func.Parameters, 1, parms, 0, parms.Length);
                        BuildFunction(sb, new SqlFunction(func.SystemType, func.Name, func.Parameters[0],
                                          new SqlFunction(func.SystemType, func.Name, parms)));
                        return;
                    }

                    var sc = new SqlQuery.SearchCondition();

                    sc.Conditions.Add(new SqlQuery.Condition(false, new SqlQuery.Predicate.IsNull(func.Parameters[0], false)));

                    func = new SqlFunction(func.SystemType, "IIF", sc, func.Parameters[1], func.Parameters[0]);

                    break;
            }

            base.BuildFunction(sb, func);
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:30,代码来源:SqlServer2012SqlProvider.cs

示例2: BuildSkip

        static void BuildSkip(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression prevSkipValue, ISqlExpression expr)
        {
            var sql = sequence.SqlQuery;

            builder.SqlProvider.SqlQuery = sql;

            sql.Select.Skip(expr);

            builder.SqlProvider.SqlQuery = sql;

            if (sql.Select.TakeValue != null)
            {
                if (builder.DataContextInfo.SqlProviderFlags.GetIsSkipSupportedFlag(sql) ||
                    !builder.DataContextInfo.SqlProviderFlags.IsTakeSupported)
                    sql.Select.Take(builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), sql.Select.TakeValue, "-", sql.Select.SkipValue, Precedence.Additive)));

                if (prevSkipValue != null)
                    sql.Select.Skip(builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), prevSkipValue, "+", sql.Select.SkipValue, Precedence.Additive)));
            }

            if (!builder.DataContextInfo.SqlProviderFlags.GetAcceptsTakeAsParameterFlag(sql))
            {
                var p = sql.Select.SkipValue as SqlParameter;

                if (p != null)
                    p.IsQueryParameter = false;
            }
        }
开发者ID:henleygao,项目名称:linq2db,代码行数:32,代码来源:TakeSkipBuilder.cs

示例3: ParseSkip

		static void ParseSkip(ExpressionParser parser, IParseContext sequence, ISqlExpression prevSkipValue, ISqlExpression expr)
		{
			var sql = sequence.SqlQuery;

			parser.SqlProvider.SqlQuery = sql;

			sql.Select.Skip(expr);

			parser.SqlProvider.SqlQuery = sql;

			if (sql.Select.TakeValue != null)
			{
				if (parser.SqlProvider.IsSkipSupported || !parser.SqlProvider.IsTakeSupported)
					sql.Select.Take(parser.Convert(
						sequence,
						new SqlBinaryExpression(typeof(int), sql.Select.TakeValue, "-", sql.Select.SkipValue, Precedence.Additive)));

				if (prevSkipValue != null)
					sql.Select.Skip(parser.Convert(
						sequence,
						new SqlBinaryExpression(typeof(int), prevSkipValue, "+", sql.Select.SkipValue, Precedence.Additive)));
			}

			if (!parser.SqlProvider.TakeAcceptsParameter)
			{
				var p = sql.Select.SkipValue as SqlParameter;

				if (p != null)
					p.IsQueryParameter = false;
			}
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:31,代码来源:TakeSkipParser.cs

示例4: ConvertArgs

		protected ISqlExpression[] ConvertArgs(MemberInfo member, ISqlExpression[] args)
		{
			if (member is MethodInfo)
			{
				var method = (MethodInfo)member;

				if (method.DeclaringType.IsGenericType)
					args = args.Concat(method.DeclaringType.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();

				if (method.IsGenericMethod)
					args = args.Concat(method.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray();
			}

			if (ArgIndices != null)
			{
				var idxs = new ISqlExpression[ArgIndices.Length];

				for (var i = 0; i < ArgIndices.Length; i++)
					idxs[i] = args[ArgIndices[i]];

				return idxs;
			}

			return args;
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:25,代码来源:SqlFunctionAttribute.cs

示例5: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			switch (expr.ElementType)
			{
				case QueryElementType.SqlBinaryExpression:
					{
						var be = (SqlBinaryExpression)expr;

						switch (be.Operation)
						{
							case "%":
								{
									var type1 = TypeHelper.GetUnderlyingType(be.Expr1.SystemType);

									if (type1 == typeof(double) || type1 == typeof(float))
									{
										return new SqlBinaryExpression(
											be.Expr2.SystemType,
											new SqlFunction(typeof(int), "Convert", SqlDataType.Int32, be.Expr1),
											be.Operation,
											be.Expr2);
									}

									break;
								}
						}

						break;
					}

				case QueryElementType.SqlFunction:
					{
						var func = (SqlFunction)expr;

						switch (func.Name)
						{
							case "Convert" :
								{
									if (TypeHelper.GetUnderlyingType(func.SystemType) == typeof(ulong) &&
										TypeHelper.IsFloatType(func.Parameters[1].SystemType))
										return new SqlFunction(
											func.SystemType,
											func.Name,
											func.Precedence,
											func.Parameters[0],
											new SqlFunction(func.SystemType, "Floor", func.Parameters[1]));

									break;
								}
						}

						break;
					}
			}

			return expr;
		}
开发者ID:luoshulin,项目名称:bltoolkit,代码行数:59,代码来源:MSSqlSqlProvider.cs

示例6: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlFunction)
				return ConvertConvertFunction((SqlFunction)expr);

			return expr;
		}
开发者ID:Convey-Compliance,项目名称:linq2db,代码行数:9,代码来源:SqlServer2000SqlOptimizer.cs

示例7: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlBinaryExpression)
			{
				var be = (SqlBinaryExpression)expr;

				switch (be.Operation)
				{
					case "^": return new SqlBinaryExpression(be.SystemType, be.Expr1, "#", be.Expr2);
					case "+": return be.SystemType == typeof(string)? new SqlBinaryExpression(be.SystemType, be.Expr1, "||", be.Expr2, be.Precedence): expr;
				}
			}
			else if (expr is SqlFunction)
			{
				var func = (SqlFunction) expr;

				switch (func.Name)
				{
					case "Convert"   :
						if (TypeHelper.GetUnderlyingType(func.SystemType) == typeof(bool))
						{
							var ex = AlternativeConvertToBoolean(func, 1);
							if (ex != null)
								return ex;
						}

						return new SqlExpression(func.SystemType, "Cast({0} as {1})", Precedence.Primary, FloorBeforeConvert(func), func.Parameters[0]);

					case "CharIndex" :
						return func.Parameters.Length == 2?
							new SqlExpression(func.SystemType, "Position({0} in {1})", Precedence.Primary, func.Parameters[0], func.Parameters[1]):
							Add<int>(
								new SqlExpression(func.SystemType, "Position({0} in {1})", Precedence.Primary, func.Parameters[0],
									ConvertExpression(new SqlFunction(typeof(string), "Substring",
										func.Parameters[1],
										func.Parameters[2],
										Sub<int>(ConvertExpression(new SqlFunction(typeof(int), "Length", func.Parameters[1])), func.Parameters[2])))),
								Sub(func.Parameters[2], 1));
				}
			}
			else if (expr is SqlExpression)
			{
				var e = (SqlExpression)expr;

				if (e.Expr.StartsWith("Extract(DOW"))
					return Inc(new SqlExpression(expr.SystemType, e.Expr.Replace("Extract(DOW", "Extract(Dow"), e.Parameters));

				if (e.Expr.StartsWith("Extract(Millisecond"))
					return new SqlExpression(expr.SystemType, "Cast(To_Char({0}, 'MS') as int)", e.Parameters);
			}

			return expr;
		}
开发者ID:pbludov,项目名称:bltoolkit,代码行数:55,代码来源:PostgreSQLSqlProvider.cs

示例8: GenerateRsSizeLimitingParametersForPaging

        protected override IDacParameter[] GenerateRsSizeLimitingParametersForPaging(IQuery query, ISqlExpression sqlExpression)
        {
            var skipRows = (query.Paging.PageIndex * query.Paging.PageSize);
            var takeRows = (skipRows + query.Paging.PageSize);

            return new IDacParameter[] 
            {
                new DacParameter("skipRows", skipRows),
                new DacParameter("takeRows", takeRows)
            };
        }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:11,代码来源:Sql2005QueryGenerator.cs

示例9: GenerateOrderByMembersString

		protected virtual string GenerateOrderByMembersString(IQuery queryCommand, ISqlExpression sqlExpression)
		{
			var sortings = sqlExpression.SortingMembers.Select(
				sorting => (sorting.MemberPath != IndexStorageSchema.Fields.StructureId.Name)
					? string.Format("min(mem{0}.[{1}]) mem{0}", sorting.Index, sorting.IndexStorageColumnName)
					: string.Empty).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

            return sortings.Length == 0
                ? string.Empty
				: string.Join(", ", sortings);
        }
开发者ID:BlackMael,项目名称:SisoDb-Provider,代码行数:11,代码来源:DbQueryGenerator.cs

示例10: ConvertEmptyStringToNullIfNeeded

		private static void ConvertEmptyStringToNullIfNeeded(ISqlExpression expr)
		{
			var sqlParameter = expr as SqlParameter;
			var sqlValue     = expr as SqlValue;

			if (sqlParameter != null && sqlParameter.Value is string && sqlParameter.Value.ToString() == "")
				sqlParameter.Value = null;

			if (sqlValue != null && sqlValue.Value is string && sqlValue.Value.ToString() == "")
				sqlValue.Value = null;
		}
开发者ID:yallie,项目名称:linq2db,代码行数:11,代码来源:OracleSqlBuilder.cs

示例11: GenerateOrderByString

		protected virtual string GenerateOrderByString(IQuery query, ISqlExpression sqlExpression)
		{
			var sortings = sqlExpression.SortingMembers.Select(
				sorting => (sorting.MemberPath != IndexStorageSchema.Fields.StructureId.Name)
				           	? string.Format("mem{0} {1}", sorting.Index, sorting.Direction)
							: string.Format("s.[{0}] {1}", IndexStorageSchema.Fields.StructureId.Name, sorting.Direction)).ToArray();

            return sortings.Length == 0
                ? string.Empty
                : string.Join(", ", sortings);
        }
开发者ID:BlackMael,项目名称:SisoDb-Provider,代码行数:11,代码来源:DbQueryGenerator.cs

示例12: GeneratePagingString

		protected override string GeneratePagingString(IQuery query, ISqlExpression sqlExpression)
        {
			if (!query.HasPaging)
                return string.Empty;

            var s = string.Join(", ", sqlExpression.SortingMembers.Select(
				sorting => sorting.MemberPath != IndexStorageSchema.Fields.StructureId.Name 
					? string.Format("min(mem{0}.[{1}]) {2}", sorting.Index, sorting.IndexStorageColumnName, sorting.Direction)
					: string.Format("s.[{0}] {1}", IndexStorageSchema.Fields.StructureId.Name, sorting.Direction)));
            
            return string.Format("row_number() over (order by {0}) RowNum", s);
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:12,代码来源:Sql2005QueryGenerator.cs

示例13: GeneratePagingParameters

        protected override IDacParameter[] GeneratePagingParameters(IQuery query, ISqlExpression sqlExpression)
        {
            if (!query.HasPaging)
                return new IDacParameter[0];

            var takeFromRowNum = (query.Paging.PageIndex * query.Paging.PageSize) + 1;
            var takeToRowNum = (takeFromRowNum + query.Paging.PageSize) - 1;

            return new IDacParameter[]
            {
                new DacParameter("pagingFrom", takeFromRowNum),
                new DacParameter("pagingTo", takeToRowNum)
            };
        }
开发者ID:MikaelEliasson,项目名称:SisoDb-Provider,代码行数:14,代码来源:Sql2005QueryGenerator.cs

示例14: ConvertExpression

		public override ISqlExpression ConvertExpression(ISqlExpression expr)
		{
			expr = base.ConvertExpression(expr);

			if (expr is SqlFunction)
			{
				var func = expr as SqlFunction;
				if (func.Name == "Convert")
				{
					var ftype = func.SystemType.ToUnderlying();

					if (ftype == typeof(bool))
					{
						var ex = AlternativeConvertToBoolean(func, 1);
						if (ex != null)
							return ex;
					}
					return new SqlExpression(func.SystemType, "Cast({0} as {1})", Precedence.Primary, FloorBeforeConvert(func), func.Parameters[0]);
				}
			}
			else if (expr is SqlBinaryExpression)
			{
				var be = expr as SqlBinaryExpression;

				switch (be.Operation)
				{
					case "%":
						return new SqlFunction(be.SystemType, "MOD", be.Expr1, be.Expr2);
					case "&": 
						return new SqlFunction(be.SystemType, "BITAND", be.Expr1, be.Expr2);
					case "|":
						return Sub(
							Add(be.Expr1, be.Expr2, be.SystemType),
							new SqlFunction(be.SystemType, "BITAND", be.Expr1, be.Expr2),
							be.SystemType);
					case "^": // (a + b) - BITAND(a, b) * 2
						return Sub(
							Add(be.Expr1, be.Expr2, be.SystemType),
							Mul(new SqlFunction(be.SystemType, "BITAND", be.Expr1, be.Expr2), 2),
							be.SystemType);
					case "+": 
						return be.SystemType == typeof(string) ? 
							new SqlBinaryExpression(be.SystemType, be.Expr1, "||", be.Expr2, be.Precedence) : 
							expr;
				}
			}

			return expr;
		}
开发者ID:Convey-Compliance,项目名称:linq2db,代码行数:49,代码来源:SapHanaSqlOptimizer.cs

示例15: CreateSqlQueryFormatter

 protected override SqlQueryFormatter CreateSqlQueryFormatter(IQuery query, ISqlExpression sqlExpression)
 {
     return new SqlQueryFormatter
     {
         Start = GenerateStartString(query, sqlExpression),
         End = GenerateEndString(query, sqlExpression),
         Take = GenerateTakeString(query),
         OrderByMembers = GenerateOrderByMembersString(query, sqlExpression),
         MainStructureTable = query.StructureSchema.GetStructureTableName(),
         WhereAndSortingJoins = GenerateWhereAndSortingJoins(query, sqlExpression),
         WhereCriteria = GenerateWhereCriteriaString(sqlExpression),
         OrderBy = GenerateOrderByString(query, sqlExpression),
         Paging = GeneratePagingString(query, sqlExpression).PrependWith(", "),
     };
 }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:15,代码来源:Sql2005QueryGenerator.cs


注:本文中的ISqlExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。