src/Shared/EntityFramework/Core/Mapping/ViewGeneration/Structures/ScalarRestriction.cs
// <summary>
// Common code for <see cref="AsEsql" /> and <see cref="AsUserString" /> methods.
// </summary>
Common code for  and  methods.
Common code for and methods .
private StringBuilder ToStringHelper(StringBuilder inputBuilder, string blockAlias, bool skipIsNotNull, bool userString)
        {
            var builder = new StringBuilder();
            AsCql(
                (negated, domainValues) =>
                    {
                        if (userString)
                        {
                            negated.AsUserString(builder, blockAlias, domainValues, RestrictedMemberSlot.MemberPath, skipIsNotNull);
                        }
                        else
                        {
                            negated.AsEsql(builder, blockAlias, domainValues, RestrictedMemberSlot.MemberPath, skipIsNotNull);
                        }
                    },
                (domainValues) =>
                    {
                        Debug.Assert(domainValues.Count > 0, "domain must not be empty");
                        RestrictedMemberSlot.MemberPath.AsEsql(builder, blockAlias);
                        if (domainValues.Count == 1)
                        {
                            builder.Append(" = ");
                            if (userString)
                            {
                                domainValues.Single().ToCompactString(builder);
                            }
                            else
                            {
                                domainValues.Single().AsEsql(builder, RestrictedMemberSlot.MemberPath, blockAlias);
                            }
                        }
                        else
                        {
                            builder.Append(" IN {");
                            var first = true;
                            foreach (var constant in domainValues)
                            {
                                if (!first)
                                {
                                    builder.Append(", ");
                                }
                                if (userString)
                                {
                                    constant.ToCompactString(builder);
                                }
                                else
                                {
                                    constant.AsEsql(builder, RestrictedMemberSlot.MemberPath, blockAlias);
                                }
                                first = false;
                            }
                            builder.Append('}');
                        }
                    },
                () =>
                    {
                        var leftExprEmpty = builder.Length == 0;
                        builder.Insert(0, '(');
                        if (!leftExprEmpty)
                        {
                            builder.Append(" AND ");
                        }
                        if (userString)
                        {
                            RestrictedMemberSlot.MemberPath.ToCompactString(builder, Strings.ViewGen_EntityInstanceToken);
                            builder.Append(" is not NULL)"); 
                        }
                        else
                        {
                            RestrictedMemberSlot.MemberPath.AsEsql(builder, blockAlias);
                            builder.Append(" IS NOT NULL)"); 
                        }
                    },
                () =>
                    {
                        var rightExprEmpty = builder.Length == 0;
                        var varIsNullBuilder = new StringBuilder();
                        if (!rightExprEmpty)
                        {
                            varIsNullBuilder.Append('(');
                        }
                        if (userString)
                        {
                            RestrictedMemberSlot.MemberPath.ToCompactString(varIsNullBuilder, blockAlias);
                            varIsNullBuilder.Append(" is NULL");
                        }
                        else
                        {
                            RestrictedMemberSlot.MemberPath.AsEsql(varIsNullBuilder, blockAlias);
                            varIsNullBuilder.Append(" IS NULL");
                        }
                        if (!rightExprEmpty)
                        {
                            varIsNullBuilder.Append(" OR ");
                        }
                        builder.Insert(0, varIsNullBuilder.ToString());
                        if (!rightExprEmpty)
                        {
                            builder.Append(')');
                        }
                    },
                skipIsNotNull);
            inputBuilder.Append(builder);
            return inputBuilder;
        }
private StringBuilder ToStringHelper ( StringBuilder inputBuilder , string blockAlias , bool skipIsNotNull , bool userString ) { var builder = new StringBuilder ( ) ; AsCql ( ( negated , domainValues ) => { if ( userString ) { negated . AsUserString ( builder , blockAlias , domainValues , RestrictedMemberSlot . MemberPath , skipIsNotNull ) ; } else { negated . AsEsql ( builder , blockAlias , domainValues , RestrictedMemberSlot . MemberPath , skipIsNotNull ) ; } } , ( domainValues ) => { Debug . Assert ( domainValues . Count > 0 , " " ) ; RestrictedMemberSlot . MemberPath . AsEsql ( builder , blockAlias ) ; if ( domainValues . Count == 1 ) { builder . Append ( " " ) ; if ( userString ) { domainValues . Single ( ) . ToCompactString ( builder ) ; } else { domainValues . Single ( ) . AsEsql ( builder , RestrictedMemberSlot . MemberPath , blockAlias ) ; } } else { builder . Append ( " " ) ; var first = true ; foreach ( var constant in domainValues ) { if ( ! first ) { builder . Append ( " " ) ; } if ( userString ) { constant . ToCompactString ( builder ) ; } else { constant . AsEsql ( builder , RestrictedMemberSlot . MemberPath , blockAlias ) ; } first = false ; } builder . Append ( ' ' ) ; } } , ( ) => { var leftExprEmpty = builder . Length == 0 ; builder . Insert ( 0 , ' ' ) ; if ( ! leftExprEmpty ) { builder . Append ( " " ) ; } if ( userString ) { RestrictedMemberSlot . MemberPath . ToCompactString ( builder , Strings . ViewGen_EntityInstanceToken ) ; builder . Append ( " " ) ; } else { RestrictedMemberSlot . MemberPath . AsEsql ( builder , blockAlias ) ; builder . Append ( " " ) ; } } , ( ) => { var rightExprEmpty = builder . Length == 0 ; var varIsNullBuilder = new StringBuilder ( ) ; if ( ! rightExprEmpty ) { varIsNullBuilder . Append ( ' ' ) ; } if ( userString ) { RestrictedMemberSlot . MemberPath . ToCompactString ( varIsNullBuilder , blockAlias ) ; varIsNullBuilder . Append ( " " ) ; } else { RestrictedMemberSlot . MemberPath . AsEsql ( varIsNullBuilder , blockAlias ) ; varIsNullBuilder . Append ( " " ) ; } if ( ! rightExprEmpty ) { varIsNullBuilder . Append ( " " ) ; } builder . Insert ( 0 , varIsNullBuilder . ToString ( ) ) ; if ( ! rightExprEmpty ) { builder . Append ( ' ' ) ; } } , skipIsNotNull ) ; inputBuilder . Append ( builder ) ; return inputBuilder ; }
Common code for  and  methods.
Common code for and methods .
// Due to the varIsNotNull and varIsNull actions, we cannot build incrementally. // So we use a local StringBuilder - it should not be that inefficient (one extra copy). // negatedConstantAsCql action // varInDomain action // Single value // Multiple values // varIsNotNull action // (leftExpr AND var IS NOT NULL) // plus the closing bracket // plus the closing bracket // varIsNull action // (var IS NULL OR rightExpr)
inputBuilder
StringBuilder
blockAlias
string
skipIsNotNull
bool
userString
bool