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


C# DbExpression.IsNull方法代码示例

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


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

示例1: ImplementEqualityUnknownArguments

 // Generate an equality expression where the values of the left and right operands are completely unknown 
 private DbExpression ImplementEqualityUnknownArguments(DbExpression left, DbExpression right, EqualsPattern pattern)
 {
     switch (pattern)
     {
         case EqualsPattern.Store: // left EQ right
             return left.Equal(right);
         case EqualsPattern.PositiveNullEqualityNonComposable: // for Joins
             return left.Equal(right).Or(left.IsNull().And(right.IsNull()));
         case EqualsPattern.PositiveNullEqualityComposable:
             {
                 var bothNotNull = left.Equal(right);
                 var bothNull = left.IsNull().And(right.IsNull());
                 if (!_funcletizer.RootContext.ContextOptions.UseCSharpNullComparisonBehavior)
                 {
                     return bothNotNull.Or(bothNull); // same as EqualsPattern.PositiveNullEqualityNonComposable
                 }
                 // add more logic to avoid undefined result for true clr semantics, ensuring composability
                 // (left EQ right AND NOT (left IS NULL OR right IS NULL)) OR (left IS NULL AND right IS NULL)
                 var anyOneIsNull = left.IsNull().Or(right.IsNull());
                 return (bothNotNull.And(anyOneIsNull.Not())).Or(bothNull);
             }
         default:
             Debug.Fail("unexpected pattern");
             return null;
     }
 }
开发者ID:jesusico83,项目名称:Telerik,代码行数:27,代码来源:ExpressionConverter.cs

示例2: ImplementEqualityConstantAndUnknown

 // Generate an equality expression with one unknown operator and 
 private DbExpression ImplementEqualityConstantAndUnknown(
     DbConstantExpression constant, DbExpression unknown, EqualsPattern pattern)
 {
     switch (pattern)
     {
         case EqualsPattern.Store:
         case EqualsPattern.PositiveNullEqualityNonComposable: // for Joins                    
             return constant.Equal(unknown); // either both are non-null, or one is null and the predicate result is undefined
         case EqualsPattern.PositiveNullEqualityComposable:
             if (!_funcletizer.RootContext.ContextOptions.UseCSharpNullComparisonBehavior)
             {
                 return constant.Equal(unknown); // same as EqualsPattern.PositiveNullEqualityNonComposable
             }
             return constant.Equal(unknown).And(unknown.IsNull().Not());
         // add more logic to avoid undefined result for true clr semantics
         default:
             Debug.Fail("unknown pattern");
             return null;
     }
 }
开发者ID:jesusico83,项目名称:Telerik,代码行数:21,代码来源:ExpressionConverter.cs

示例3: ImplementEquality

 // For comparisons, where the left and right side are nullable or not nullable, 
 // here are the (compositionally safe) null equality predicates:
 // -- x NOT NULL, y NULL
 // x = y AND  NOT (y IS NULL)
 // -- x NULL, y NULL
 // (x = y AND  (NOT (x IS NULL OR y IS NULL))) OR (x IS NULL AND y IS NULL)
 // -- x NOT NULL, y NOT NULL
 // x = y
 // -- x NULL, y NOT NULL
 // x = y AND  NOT (x IS NULL)
 private DbExpression ImplementEquality(DbExpression left, DbExpression right, EqualsPattern pattern)
 {
     switch (left.ExpressionKind)
     {
         case DbExpressionKind.Constant:
             switch (right.ExpressionKind)
             {
                 case DbExpressionKind.Constant: // constant EQ constant
                     return left.Equal(right);
                 case DbExpressionKind.Null: // null EQ constant --> false
                     return DbExpressionBuilder.False;
                 default:
                     return ImplementEqualityConstantAndUnknown((DbConstantExpression)left, right, pattern);
             }
         case DbExpressionKind.Null:
             switch (right.ExpressionKind)
             {
                 case DbExpressionKind.Constant: // null EQ constant --> false
                     return DbExpressionBuilder.False;
                 case DbExpressionKind.Null: // null EQ null --> true
                     return DbExpressionBuilder.True;
                 default: // null EQ right --> right IS NULL
                     return right.IsNull();
             }
         default: // unknown
             switch (right.ExpressionKind)
             {
                 case DbExpressionKind.Constant:
                     return ImplementEqualityConstantAndUnknown((DbConstantExpression)right, left, pattern);
                 case DbExpressionKind.Null: //  left EQ null --> left IS NULL
                     return left.IsNull();
                 default:
                     return ImplementEqualityUnknownArguments(left, right, pattern);
             }
     }
 }
开发者ID:jesusico83,项目名称:Telerik,代码行数:46,代码来源:ExpressionConverter.cs

示例4: CreateIsNullExpression

 // <summary>
 // Creates an implementation of IsNull. Throws exception when operand type is not supported.
 // </summary>
 private static DbExpression CreateIsNullExpression(DbExpression operand, Type operandClrType)
 {
     VerifyTypeSupportedForComparison(operandClrType, operand.ResultType, null);
     return operand.IsNull();
 }
开发者ID:jesusico83,项目名称:Telerik,代码行数:8,代码来源:ExpressionConverter.cs

示例5: StripNull

            internal static CqtExpression StripNull(LinqExpression sourceExpression, 
                DbExpression inputExpression, DbExpression outputExpression)
            {
                if (sourceExpression.IsNullConstant())
                {
                    return DbExpressionBuilder.Constant(string.Empty);
                }

                if (sourceExpression.NodeType == ExpressionType.Constant)
                {
                    return outputExpression;
                }

                // converts evaluated null values to empty string, nullable primitive properties etc.
                var castNullToEmptyString = DbExpressionBuilder.Case(
                    new[] { inputExpression.IsNull() },
                    new[] { DbExpressionBuilder.Constant(string.Empty) },
                    outputExpression);
                return castNullToEmptyString;
            }
开发者ID:jesusico83,项目名称:Telerik,代码行数:20,代码来源:StringTranslatorUtil.cs

示例6: RewriteRow


//.........这里部分代码省略.........
            for (var idx = 0; idx < rowType.Properties.Count; idx++)
            {
                // Retrieve the property that represents the current column
                var columnProp = rowType.Properties[idx];

                // Construct an expression that defines the current column.
                DbExpression columnExpr = null;
                if (newRow != null)
                {
                    // For a row-constructing NewInstance expression, the corresponding argument can simply be used
                    columnExpr = newRow.Arguments[idx];
                }
                else
                {
                    // For all other expressions the property corresponding to the column name must be retrieved
                    // from the row-typed expression
                    columnExpr = expression.Property(columnProp.Name);
                }

                var spannedColumn = Rewrite(columnExpr);
                if (!ReferenceEquals(spannedColumn, columnExpr))
                {
                    // If so, then update the dictionary of column index to span information
                    if (null == spannedColumns)
                    {
                        spannedColumns = new Dictionary<int, DbExpression>();
                    }

                    spannedColumns[idx] = spannedColumn;
                }
                else
                {
                    // Otherwise, update the dictionary of column index to unmodified expression
                    if (null == unmodifiedColumns)
                    {
                        unmodifiedColumns = new Dictionary<int, DbExpression>();
                    }

                    unmodifiedColumns[idx] = columnExpr;
                }
            }

            // A new expression need only be built if at least one column was spanned
            if (null == spannedColumns)
            {
                // No columns were spanned, indicate that the original expression should remain.
                return expression;
            }
            else
            {
                // At least one column was spanned, so build a new row constructor that defines the new row, including spanned columns.
                var columnArguments = new List<DbExpression>(rowType.Properties.Count);
                var properties = new List<EdmProperty>(rowType.Properties.Count);
                for (var idx = 0; idx < rowType.Properties.Count; idx++)
                {
                    var columnProp = rowType.Properties[idx];
                    DbExpression columnDef = null;
                    if (!spannedColumns.TryGetValue(idx, out columnDef))
                    {
                        columnDef = unmodifiedColumns[idx];
                    }
                    columnArguments.Add(columnDef);
                    properties.Add(new EdmProperty(columnProp.Name, columnDef.ResultType));
                }

                // Copy over any eLinq initializer metadata (if present, or null if not).
                // Note that this initializer metadata does not strictly match the new row type
                // that includes spanned columns, but will be correct once the object materializer
                // has interpreted the query results to produce the correct value for each colum.
                var rewrittenRow = new RowType(properties, rowType.InitializerMetadata);
                var rewrittenRowTypeUsage = TypeUsage.Create(rewrittenRow);
                DbExpression rewritten = rewrittenRowTypeUsage.New(columnArguments);

                // SQLBUDT #554182: If we insert a new projection we should should make sure to 
                // not interfere with the nullability of the input. 
                // In particular, if the input row is null and we construct a new row as a projection over its columns
                // we would get a row consisting of nulls, instead of a null row. 
                // Thus, given an input X, we rewritte it as:  if (X is null) then NULL else rewritten.
                if (newRow == null)
                {
                    DbExpression condition = expression.IsNull();
                    DbExpression nullExpression = rewrittenRowTypeUsage.Null();
                    rewritten = DbExpressionBuilder.Case(
                        new List<DbExpression>(new[] { condition }),
                        new List<DbExpression>(new[] { nullExpression }),
                        rewritten);
                }

                // Add an entry to the spanned row type => original row type map for the new row type.
                AddSpannedRowType(rewrittenRow, expression.ResultType);

                if (lambdaExpression != null
                    && newRow != null)
                {
                    rewritten = DbLambda.Create(rewritten, lambdaExpression.Lambda.Variables).Invoke(lambdaExpression.Arguments);
                }

                return rewritten;
            }
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:101,代码来源:ObjectSpanRewriter.cs


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