System.Data.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.Case(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Data.Common.CommandTrees.DbExpression)

Here are the examples of the csharp api class System.Data.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.Case(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Data.Common.CommandTrees.DbExpression) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

15 Examples 7

1. Example

View license
internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
        {
            if (m_expr.IsTrue || m_expr.IsFalse)
            {
                return m_expr.AsCqt(row);
            }
            else
            {
                // Produce "CASE WHEN boolExpr THEN True ELSE False END" in order to enforce the two-state boolean logic:
                // if boolExpr returns the boolean Unknown, it gets converted to boolean False.
                return DbExpressionBuilder.Case(new DbExpression[] { m_expr.AsCqt(row) }, new DbExpression[] { DbExpressionBuilder.True }, DbExpressionBuilder.False);
            }
        }

2. Example

Project: referencesource
Source File: Translator.cs
View license
protected override DbExpression TypedTranslate(ExpressionConverter parent, ConditionalExpression linq)
            {
                // translate Test ? IfTrue : IfFalse --> CASE WHEN Test THEN IfTrue ELSE IfFalse
                List<DbExpression> whenExpressions = new List<DbExpression>(1);
                whenExpressions.Add(parent.TranslateExpression(linq.Test));
                List<DbExpression> thenExpressions = new List<DbExpression>(1);
                thenExpressions.Add(parent.TranslateExpression(linq.IfTrue));
                DbExpression elseExpression = parent.TranslateExpression(linq.IfFalse);
                return DbExpressionBuilder.Case(whenExpressions, thenExpressions, elseExpression);
            }

3. Example

Project: referencesource
Source File: Translator.cs
View license
protected override DbExpression TranslateBinary(ExpressionConverter parent, DbExpression left, DbExpression right, BinaryExpression linq)
            {
                // left ?? right gets translated to:
                // CASE WHEN IsNull(left) THEN right ELSE left

                // construct IsNull
                DbExpression isNull = parent.CreateIsNullExpression(left, linq.Left.Type);

                // construct case expression
                List<DbExpression> whenExpressions = new List<DbExpression>(1);
                whenExpressions.Add(isNull);
                List<DbExpression> thenExpressions = new List<DbExpression>(1);
                thenExpressions.Add(right);
                DbExpression caseExpression = DbExpressionBuilder.Case(whenExpressions,
                    thenExpressions, left);

                return caseExpression;
            }

4. Example

Project: referencesource
Source File: ViewSimplifier.cs
View license
private static DbExpression SimplifyCaseStatement(DbExpression expression)
        {
            DbCaseExpression caseExpression = (DbCaseExpression)expression;

            // try simplifying predicates
            bool predicateSimplified = false;
            List<DbExpression> rewrittenPredicates = new List<DbExpression>(caseExpression.When.Count);
            foreach (var when in caseExpression.When)
            {
                DbExpression simplifiedPredicate;
                if (TrySimplifyPredicate(when, out simplifiedPredicate))
                {
                    rewrittenPredicates.Add(simplifiedPredicate);
                    predicateSimplified = true;
                }
                else
                {
                    rewrittenPredicates.Add(when);
                }
            }

            if (!predicateSimplified) { return null; }

            caseExpression = DbExpressionBuilder.Case(rewrittenPredicates, caseExpression.Then, caseExpression.Else);
            return caseExpression;
        }

5. Example

View license
public override DbExpression Visit(DbCaseExpression expression)
        {
            EntityUtil.CheckArgumentNull(expression, "expression");

            DbExpression result = expression;

            IList<DbExpression> newWhens = this.VisitExpressionList(expression.When);
            IList<DbExpression> newThens = this.VisitExpressionList(expression.Then);
            DbExpression newElse = this.VisitExpression(expression.Else);

            if (!object.ReferenceEquals(expression.When, newWhens) ||
                !object.ReferenceEquals(expression.Then, newThens) ||
                !object.ReferenceEquals(expression.Else, newElse))
            {
                result = CqtBuilder.Case(newWhens, newThens, newElse);
            }
            NotifyIfChanged(expression, result);
            return result;
        }

6. Example

Project: referencesource
Source File: CaseStatement.cs
View license
internal DbExpression AsCqt(DbExpression row, IEnumerable<WithRelationship> withRelationships)
        {
            // Generate the Case WHEN .. THEN ..., WHEN ... THEN ..., END
            List<DbExpression> conditions = new List<DbExpression>();
            List<DbExpression> values = new List<DbExpression>();
            foreach (CaseStatement.WhenThen clause in this.Clauses)
            {
                conditions.Add(clause.Condition.AsCqt(row));
                values.Add(CaseSlotValueAsCqt(row, clause.Value, this.MemberPath, withRelationships));
            }

            // Generate ELSE
            DbExpression elseValue = this.ElseValue != null ?
                CaseSlotValueAsCqt(row, this.ElseValue, this.MemberPath, withRelationships) :
                Constant.Null.AsCqt(row, this.MemberPath);

            if (this.Clauses.Count > 0)
            {
                return DbExpressionBuilder.Case(conditions, values, elseValue);
            }
            else
            {
                Debug.Assert(elseValue != null, "CASE statement with no WHEN/THENs must have ELSE.");
                return elseValue;
            }
        }

7. Example

View license
internal static CqtExpression AddDefaultCase(ExpressionConverter parent, CqtExpression element, Type elementType)
                {
                    // Retrieve default value.
                    object defaultValue = TypeSystem.GetDefaultValue(elementType);
                    if (null == defaultValue)
                    {
                        // Already null, which is the implicit default for DbElementExpression
                        return element;
                    }

                    Debug.Assert(TypeSemantics.IsScalarType(element.ResultType), "Primitive or enum type expected at this point.");

                    // Otherwise, use the default value for the type
                    List<CqtExpression> whenExpressions = new List<CqtExpression>(1);

                    whenExpressions.Add(parent.CreateIsNullExpression(element, elementType));
                    List<CqtExpression> thenExpressions = new List<CqtExpression>(1);
                    thenExpressions.Add(DbExpressionBuilder.Constant(element.ResultType, defaultValue));
                    DbCaseExpression caseExpression = DbExpressionBuilder.Case(whenExpressions, thenExpressions, element);
                    return caseExpression;
                }

8. Example

Project: referencesource
Source File: CTreeGenerator.cs
View license
public override DbExpression Visit(CaseOp op, Node n)
        {
            //
            // CaseOp/n ..... /n //View Source file for more details /n }

9. Example

Project: referencesource
Source File: ViewSimplifier.cs
View license
private DbExpression AddFkRelatedEntityRefs(DbExpression viewConstructor)
        {
            // I/n ..... /n //View Source file for more details /n }

10. Example

Project: referencesource
Source File: SemanticAnalyzer.cs
View license
private static ExpressionResolution ConvertCaseExpr(AST.Node expr, SemanticResolver sr)
        {
  /n ..... /n //View Source file for more details /n }

11. Example

View license
private DbExpression GenerateStructuralTypeResultMappingView(DbExpression storeFunctionInvoke, IList/n ..... /n //View Source file for more details /n }

12. Example

View license
internal override DbExpression Translate(ExpressionConverter parent, MethodCallExpression call)
    /n ..... /n //View Source file for more details /n }

13. Example

View license
private DbExpression RewriteRow(DbExpression expression, RowType rowType)
        {
            DbLa/n ..... /n //View Source file for more details /n }

14. Example

Project: referencesource
Source File: ViewSimplifier.cs
View license
private static DbExpression SimplifyNestedTphDiscriminator(DbExpression expression)
        {
      /n ..... /n //View Source file for more details /n }

15. Example

Project: referencesource
Source File: SemanticAnalyzer.cs
View license
private static Dictionary<AST.BuiltInKind, BuiltInExprConverter> CreateBuiltInExprConverter()
/n ..... /n //View Source file for more details /n }