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


C# IExpression.TrueOrNot方法代码示例

本文整理汇总了C#中IExpression.TrueOrNot方法的典型用法代码示例。如果您正苦于以下问题:C# IExpression.TrueOrNot方法的具体用法?C# IExpression.TrueOrNot怎么用?C# IExpression.TrueOrNot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IExpression的用法示例。


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

示例1: ExpressionToQuery

        /// <summary>
        /// Converts a single Expression to SQL (mapping the columns as appropriate) and appends
        /// to the given string builder.
        /// 
        /// Remember to wrap the SQL in parends if necessary.
        /// </summary>
        /// <param name="queryToAddTo">Query we're adding the expression to.</param>
        /// <param name="expr">The expression.  NOTE: It should NOT be null. This method does not check.</param>
        /// <param name="mapping">Class mapping for the class we're dealing with.</param>
        /// <param name="colPrefix">What to prefix column names with, I.E. "Table." for "Table.Column".
        ///                         May be null if no prefix is desired.  May be something other than
        ///                         the table name if the tables are being aliased.</param>
        /// <param name="booleanOperator">The boolean operator (AND or OR) to insert before
        ///                               this expression.  Blank ("") if we don't need one.</param>
        /// <returns>Whether or not this expression modified the sql string.
        ///          Typically true, but may be false for special query types 
        ///          that use other parameters for certain types of expressions.</returns>
        protected virtual bool ExpressionToQuery(SqlDaQuery queryToAddTo, IExpression expr,
            ClassMapping mapping, string colPrefix, string booleanOperator)
        {
            string col;
            Type dbDataType;
            bool trueOrNot = expr.TrueOrNot();

            // add the operator if one was specified.
            queryToAddTo.Sql.Append(booleanOperator);
            // Add some parends.
            queryToAddTo.Sql.Append("(");
            if (expr is BetweenExpression)
            {
                BetweenExpression between = (BetweenExpression)expr;
                col = colPrefix + mapping.AllDataColsByObjAttrs[between.Property];
                dbDataType = mapping.DataColTypesByObjAttr[between.Property];
                queryToAddTo.Sql.Append(col);
                queryToAddTo.Sql.Append(trueOrNot ? " >= " : " < ");
                AppendParameter(queryToAddTo, between.Min, dbDataType);
                queryToAddTo.Sql.Append(trueOrNot ? " AND " : " OR ");
                queryToAddTo.Sql.Append(col);
                queryToAddTo.Sql.Append(trueOrNot ? " <= " : " > ");
                AppendParameter(queryToAddTo, between.Max, dbDataType);
            }
            else if (expr is EqualExpression)
            {
                EqualExpression equal = (EqualExpression)expr;
                col = colPrefix + mapping.AllDataColsByObjAttrs[equal.Property];
                if (equal.Value == null)
                {
                    queryToAddTo.Sql.Append(col);
                    queryToAddTo.Sql.Append(trueOrNot ? " IS NULL" : " IS NOT NULL");
                }
                else
                {
                    queryToAddTo.Sql.Append(col);
                    queryToAddTo.Sql.Append(trueOrNot ? " = " : " <> ");
                    dbDataType = mapping.DataColTypesByObjAttr[equal.Property];
                    AppendParameter(queryToAddTo, equal.Value, dbDataType);
                }
            }
            else if (expr is EqualInsensitiveExpression)
            {
                EqualInsensitiveExpression iequal = (EqualInsensitiveExpression)expr;
                col = colPrefix + mapping.AllDataColsByObjAttrs[iequal.Property];
                if (iequal.Value == null)
                {
                    queryToAddTo.Sql.Append(col);
                    queryToAddTo.Sql.Append(trueOrNot ? " IS NULL" : " IS NOT NULL");
                }
                else
                {
                    string lower = _connDesc.LowerCaseFunction();
                    queryToAddTo.Sql.Append(lower).Append("(");
                    queryToAddTo.Sql.Append(col).Append(") ");
                    queryToAddTo.Sql.Append(trueOrNot ? "= " : "<> ").Append(lower).Append("(");
                    dbDataType = mapping.DataColTypesByObjAttr[iequal.Property];
                    AppendParameter(queryToAddTo, iequal.Value, dbDataType);
                    queryToAddTo.Sql.Append(")");
                }
            }
            else if (expr is GreaterExpression)
            {
                GreaterExpression greater = (GreaterExpression)expr;
                queryToAddTo.Sql.Append(colPrefix);
                queryToAddTo.Sql.Append(mapping.AllDataColsByObjAttrs[greater.Property]);
                queryToAddTo.Sql.Append(trueOrNot ? " > " : " <= ");
                dbDataType = mapping.DataColTypesByObjAttr[greater.Property];
                AppendParameter(queryToAddTo, greater.Value, dbDataType);
            }
            else if (expr is LesserExpression)
            {
                LesserExpression lesser = (LesserExpression)expr;
                queryToAddTo.Sql.Append(colPrefix);
                queryToAddTo.Sql.Append(mapping.AllDataColsByObjAttrs[lesser.Property]);
                queryToAddTo.Sql.Append(trueOrNot ? " < " : " >= ");
                dbDataType = mapping.DataColTypesByObjAttr[lesser.Property];
                AppendParameter(queryToAddTo, lesser.Value, dbDataType);
            }
            else if (expr is BitwiseAndExpression)
            {
                BitwiseAndExpression bitwise = (BitwiseAndExpression)expr;
                string colName = colPrefix + mapping.AllDataColsByObjAttrs[bitwise.Property];
//.........这里部分代码省略.........
开发者ID:azavea,项目名称:net-dao,代码行数:101,代码来源:SqlDaLayer.cs

示例2: ExpressionToQuery

        /// <summary>
        /// Converts a single Expression to SQL (mapping the columns as appropriate) and appends
        /// to the given string builder.
        /// 
        /// The expression's SQL will already be wrapped in parends, so you do not need to add them
        /// here.
        /// </summary>
        /// <param name="queryToAddTo">Query we're adding the expression to.</param>
        /// <param name="expr">The expression.  NOTE: It should NOT be null. This method does not check.</param>
        /// <param name="mapping">Class mapping for the class we're dealing with.</param>
        /// <param name="colPrefix">What to prefix column names with, I.E. "Table." for "Table.Column".
        ///                         May be null if no prefix is desired.  May be something other than
        ///                         the table name if the tables are being aliased.</param>
        /// <param name="booleanOperator">The boolean operator (AND or OR) to insert before
        ///                               this expression.  Blank ("") if we don't need one.</param>
        /// <returns>Whether or not this expression modified the sql string.
        ///          Typically true, but may be false for special query types 
        ///          that use other parameters for certain types of expressions.</returns>
        protected override bool ExpressionToQuery(SqlDaQuery queryToAddTo, IExpression expr,
            ClassMapping mapping, string colPrefix, string booleanOperator)
        {
            // All the spatial expressions we support modify the sql.
            bool retVal = true;
            bool trueOrNot = expr.TrueOrNot();
            if (expr is IntersectsExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                IntersectsExpression intersects = (IntersectsExpression)expr;
                queryToAddTo.Sql.Append("ST_Intersects(ST_GeomFromEWKT(?),");
                queryToAddTo.Params.Add(_ewktWriter.Write(intersects.Shape));
                queryToAddTo.Sql.Append(colPrefix).Append(mapping.AllDataColsByObjAttrs[intersects.Property]);
                queryToAddTo.Sql.Append(")");
            }
            else if (expr is WithinExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                WithinExpression within = (WithinExpression)expr;
                queryToAddTo.Sql.Append("ST_Contains(ST_GeomFromEWKT(?),");
                queryToAddTo.Params.Add(_ewktWriter.Write(within.Shape));
                queryToAddTo.Sql.Append(colPrefix).Append(mapping.AllDataColsByObjAttrs[within.Property]);
                queryToAddTo.Sql.Append(")");
            }
            else if (expr is ContainsExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                ContainsExpression contains = (ContainsExpression)expr;
                queryToAddTo.Sql.Append("ST_Contains(");
                queryToAddTo.Sql.Append(colPrefix).Append(mapping.AllDataColsByObjAttrs[contains.Property]);
                queryToAddTo.Sql.Append(",ST_GeomFromEWKT(?)");
                queryToAddTo.Params.Add(_ewktWriter.Write(contains.Shape));
                queryToAddTo.Sql.Append(")");
            }
            else if (expr is AbstractDistanceExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                AbstractDistanceExpression dist = (AbstractDistanceExpression)expr;

                queryToAddTo.Sql.Append("ST_Distance(");
                queryToAddTo.Sql.Append(colPrefix).Append(mapping.AllDataColsByObjAttrs[dist.Property]);
                queryToAddTo.Sql.Append(", ST_GeomFromEWKT(?))");
                queryToAddTo.Params.Add(EWKTWriter.ToPoint((IPoint)dist.Shape));
                if (dist is LesserDistanceExpression)
                {
                    queryToAddTo.Sql.Append(trueOrNot ? " < ?" : " >= ?");
                }
                else if (expr is GreaterDistanceExpression)
                {
                    queryToAddTo.Sql.Append(trueOrNot ? " > ?" : " <= ?");
                }
                else
                {
                    throw new ArgumentException("Distance expression type " +
                                                expr.GetType() + " not supported.", "expr");
                }
                queryToAddTo.Params.Add(dist.Distance);
            }
            else if (expr is AbstractDistanceSphereExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                AbstractDistanceSphereExpression dist = (AbstractDistanceSphereExpression)expr;
                if (!(dist.Shape is IPoint))
                {
                    throw new ArgumentException("Spherical distance from a non-point is not supported.");
                }

                queryToAddTo.Sql.Append("ST_distance_sphere(");
                queryToAddTo.Sql.Append(colPrefix).Append(mapping.AllDataColsByObjAttrs[dist.Property]);
                queryToAddTo.Sql.Append(", ST_GeomFromEWKT(?))");
                queryToAddTo.Params.Add(EWKTWriter.ToPoint((IPoint)dist.Shape));
                if (dist is LesserDistanceSphereExpression)
                {
                    queryToAddTo.Sql.Append(trueOrNot ? " < ?" : " >= ?");
                }
                else if (expr is GreaterDistanceSphereExpression)
                {
                    queryToAddTo.Sql.Append(trueOrNot ? " > ?" : " <= ?");
                }
                else
                {
                    throw new ArgumentException("Distance expression type " +
//.........这里部分代码省略.........
开发者ID:azavea,项目名称:net-dao-postgresql,代码行数:101,代码来源:PostgreSqlDaLayer.cs

示例3: ExpressionToQuery

        /// <summary>
        /// Converts a single Expression to SQL (mapping the columns as appropriate) and appends
        /// to the given string builder.
        /// 
        /// The expression's SQL will already be wrapped in parens, so you do not need to add them
        /// here.
        /// </summary>
        /// <param name="queryToAddTo">Query we're adding the expression to.</param>
        /// <param name="expr">The expression.  NOTE: It should NOT be null. This method does not check.</param>
        /// <param name="mapping">Class mapping for the class we're dealing with.</param>
        /// <param name="colPrefix">What to prefix column names with, I.E. "Table." for "Table.Column".
        ///                         May be null if no prefix is desired.  May be something other than
        ///                         the table name if the tables are being aliased.</param>
        /// <param name="booleanOperator">The boolean operator (AND or OR) to insert before
        ///                               this expression.  Blank ("") if we don't need one.</param>
        /// <returns>Whether or not this expression modified the sql string.
        ///          Typically true, but may be false for special query types 
        ///          that use other parameters for certain types of expressions.</returns>
        protected override bool ExpressionToQuery(SqlDaQuery queryToAddTo, IExpression expr,
                                                  ClassMapping mapping, string colPrefix, string booleanOperator)
        {
            // All the spatial expressions we support modify the sql.
            bool retVal = true;
            bool trueOrNot = expr.TrueOrNot();
            if (expr is IntersectsExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                IntersectsExpression intersects = (IntersectsExpression)expr;

                const string intersectsFormatString = "SDE.ST_Intersects({0}, {1}) = 1";

                // It is important that the input geometry is the second parameter, otherwise the
                // spatial index does not get used.
                queryToAddTo.Sql.Append(string.Format(intersectsFormatString,
                    colPrefix + mapping.AllDataColsByObjAttrs[intersects.Property],    // Shape column name
                    string.Format("SDE.ST_Geometry(?,{0})", intersects.Shape.SRID))); // geom param converted from WKT
                queryToAddTo.Params.Add(_wktWriter.Write(intersects.Shape));
            }
            else if (expr is WithinExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                WithinExpression within = (WithinExpression)expr;

                const string withinFormatString = "SDE.ST_Within({0}, {1}) = 1";

                // It is important that the input geometry is the second parameter, otherwise the
                // spatial index does not get used.
                queryToAddTo.Sql.Append(string.Format(withinFormatString,
                    colPrefix + mapping.AllDataColsByObjAttrs[within.Property],    // Shape column name
                    string.Format("SDE.ST_Geometry(?,{0})", within.Shape.SRID))); // geom param converted from WKT
                queryToAddTo.Params.Add(_wktWriter.Write(within.Shape));
            }
            else if (expr is ContainsExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                ContainsExpression contains = (ContainsExpression)expr;
                const string containsFormatString = "SDE.ST_Contains({0}, {1}) = 1";

                // It is important that the input geometry is the second parameter, otherwise the
                // spatial index does not get used.
                queryToAddTo.Sql.Append(string.Format(containsFormatString,
                    colPrefix + mapping.AllDataColsByObjAttrs[contains.Property],    // Shape column name
                    string.Format("SDE.ST_Geometry(?,{0})", contains.Shape.SRID))); // geom param converted from WKT
                queryToAddTo.Params.Add(_wktWriter.Write(contains.Shape));
            }
            else if (expr is AbstractDistanceExpression)
            {
                queryToAddTo.Sql.Append(booleanOperator);
                AbstractDistanceExpression dist = (AbstractDistanceExpression)expr;

                queryToAddTo.Sql.Append("SDE.ST_Distance(");
                queryToAddTo.Sql.Append(colPrefix).Append(mapping.AllDataColsByObjAttrs[dist.Property]);
                queryToAddTo.Sql.Append(string.Format("SDE.ST_Contains(SDE.ST_Geometry(?,{0}),", dist.Shape.SRID));
                queryToAddTo.Params.Add(WKTWriter.ToPoint(((IPoint)dist.Shape).Coordinate));
                if (dist is LesserDistanceExpression)
                {
                    queryToAddTo.Sql.Append(trueOrNot ? " < ?" : " >= ?");
                }
                else if (expr is GreaterDistanceExpression)
                {
                    queryToAddTo.Sql.Append(trueOrNot ? " > ?" : " <= ?");
                }
                else
                {
                    throw new ArgumentException("Distance expression type " +
                                                expr.GetType() + " not supported.", "expr");
                }
                queryToAddTo.Params.Add(dist.Distance);
            }
            else if (expr is AbstractDistanceSphereExpression)
            {
                throw new ArgumentException("Distance expression type " +
                                                expr.GetType() + " not supported.", "expr");
            }
            else
            {
                // The expression type does not required special handling by this subclass
                retVal = base.ExpressionToQuery(queryToAddTo, expr, mapping, colPrefix, booleanOperator);
            }
            return retVal;
//.........这里部分代码省略.........
开发者ID:kdeloach,项目名称:net-dao-odp,代码行数:101,代码来源:OdpSdeStDaLayer.cs


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