Пример #1
0
 internal override SqlExpression VisitNew(SqlNew sox)
 {
     foreach (MemberInfo info in this.IdentityMembers)
     {
         bool flag = false;
         foreach (SqlExpression expression in sox.Args)
         {
             flag = IsColumnMatch(info, expression);
             if (flag)
             {
                 break;
             }
         }
         if (!flag)
         {
             foreach (SqlMemberAssign assign in sox.Members)
             {
                 SqlExpression expr = assign.Expression;
                 flag = IsColumnMatch(info, expr);
                 if (flag)
                 {
                     break;
                 }
             }
         }
         this.IsValid &= flag;
         if (!this.IsValid)
         {
             return(sox);
         }
     }
     return(sox);
 }
Пример #2
0
 internal override SqlExpression VisitNew(SqlNew sox)
 {
     if (sox.Constructor != null)
     {
         System.Reflection.ParameterInfo[] parameters = sox.Constructor.GetParameters();
         int index = 0;
         int count = sox.Args.Count;
         while (index < count)
         {
             sox.Args[index] = this.VisitNamedExpression(sox.Args[index], parameters[index].Name);
             index++;
         }
     }
     else
     {
         int num3 = 0;
         int num4 = sox.Args.Count;
         while (num3 < num4)
         {
             sox.Args[num3] = this.VisitExpression(sox.Args[num3]);
             num3++;
         }
     }
     foreach (SqlMemberAssign assign in sox.Members)
     {
         string name = assign.Member.Name;
         if (this.useMappedNames)
         {
             name = sox.MetaType.GetDataMember(assign.Member).MappedName;
         }
         assign.Expression = this.VisitNamedExpression(assign.Expression, name);
     }
     return(sox);
 }
Пример #3
0
        public SqlExpression BuildProjection(SqlExpression item, MetaType rowType, bool allowDeferred, SqlLink link, Expression source)
        {
            if (!rowType.HasInheritance)
            {
                return(BuildProjectionInternal(item, rowType, (rowType.Table != null) ? rowType.PersistentDataMembers : rowType.DataMembers, allowDeferred, link, source));
            }
            var             list            = new List <MetaType>(rowType.InheritanceTypes);
            var             list2           = new List <SqlTypeCaseWhen>();
            SqlTypeCaseWhen when            = null;
            MetaType        inheritanceRoot = rowType.InheritanceRoot;
            MetaDataMember  discriminator   = inheritanceRoot.Discriminator;
            Type            type            = discriminator.Type;
            SqlMember       member2         = sql.Member(item, discriminator.Member);

            foreach (MetaType type3 in list)
            {
                if (type3.HasInheritanceCode)
                {
                    SqlNew typeBinding = BuildProjectionInternal(item, type3, type3.PersistentDataMembers, allowDeferred, link, source);
                    if (type3.IsInheritanceDefault)
                    {
                        when = new SqlTypeCaseWhen(null, typeBinding);
                    }
                    object        obj2  = InheritanceRules.InheritanceCodeForClientCompare(type3.InheritanceCode, member2.SqlType);
                    SqlExpression match = sql.Value(type, sql.Default(discriminator), obj2, true, source);
                    list2.Add(new SqlTypeCaseWhen(match, typeBinding));
                }
            }
            if (when == null)
            {
                throw Error.EmptyCaseNotSupported();
            }
            list2.Add(when);
            return(sql.TypeCase(inheritanceRoot.Type, inheritanceRoot, member2, list2.ToArray(), source));
        }
Пример #4
0
        internal virtual SqlExpression VisitNew(SqlNew sox)
        {
            int num   = 0;
            int count = sox.Args.Count;

            while (num < count)
            {
                sox.Args[num] = this.VisitExpression(sox.Args[num]);
                num++;
            }
            int num3 = 0;
            int num4 = sox.Members.Count;

            while (num3 < num4)
            {
                sox.Members[num3].Expression = this.VisitExpression(sox.Members[num3].Expression);
                num3++;
            }
            return(sox);
        }
Пример #5
0
            internal override SqlExpression VisitNew(SqlNew sox)
            {
                SqlExpression[]   args    = new SqlExpression[sox.Args.Count];
                SqlMemberAssign[] members = new SqlMemberAssign[sox.Members.Count];
                int index  = 0;
                int length = args.Length;

                while (index < length)
                {
                    args[index] = this.VisitExpression(sox.Args[index]);
                    index++;
                }
                int num3 = 0;
                int num4 = members.Length;

                while (num3 < num4)
                {
                    members[num3] = this.VisitMemberAssign(sox.Members[num3]);
                    num3++;
                }
                return(new SqlNew(sox.MetaType, sox.SqlType, sox.Constructor, args, sox.ArgMembers, members, sox.SourceExpression));
            }
Пример #6
0
            private SqlExpression ExpandTogether(IList <SqlExpression> exprs)
            {
                switch (exprs[0].NodeType)
                {
                case SqlNodeType.Element:
                case SqlNodeType.Grouping:
                case SqlNodeType.ClientQuery:
                case SqlNodeType.Multiset:
                    throw Error.UnionWithHierarchy();

                case SqlNodeType.Link:
                {
                    SqlLink[] linkArray = new SqlLink[exprs.Count];
                    linkArray[0] = (SqlLink)exprs[0];
                    int index = 1;
                    int count = exprs.Count;
                    while (index < count)
                    {
                        if ((exprs[index] == null) || (exprs[index].NodeType != SqlNodeType.Link))
                        {
                            throw Error.UnionIncompatibleConstruction();
                        }
                        linkArray[index] = (SqlLink)exprs[index];
                        if (((linkArray[index].KeyExpressions.Count != linkArray[0].KeyExpressions.Count) ||
                             (linkArray[index].Member != linkArray[0].Member)) ||
                            ((linkArray[index].Expansion != null) != (linkArray[0].Expansion != null)))
                        {
                            throw Error.UnionIncompatibleConstruction();
                        }
                        index++;
                    }
                    SqlExpression[]      keyExpressions = new SqlExpression[linkArray[0].KeyExpressions.Count];
                    List <SqlExpression> list11         = new List <SqlExpression>();
                    int num29 = 0;
                    int num30 = linkArray[0].KeyExpressions.Count;
                    while (num29 < num30)
                    {
                        list11.Clear();
                        int num31 = 0;
                        int num32 = exprs.Count;
                        while (num31 < num32)
                        {
                            list11.Add(linkArray[num31].KeyExpressions[num29]);
                            num31++;
                        }
                        keyExpressions[num29] = this.ExpandTogether(list11);
                        int num33 = 0;
                        int num34 = exprs.Count;
                        while (num33 < num34)
                        {
                            linkArray[num33].KeyExpressions[num29] = list11[num33];
                            num33++;
                        }
                        num29++;
                    }
                    SqlExpression expansion = null;
                    if (linkArray[0].Expansion != null)
                    {
                        list11.Clear();
                        int num35 = 0;
                        int num36 = exprs.Count;
                        while (num35 < num36)
                        {
                            list11.Add(linkArray[num35].Expansion);
                            num35++;
                        }
                        expansion = this.ExpandTogether(list11);
                        int num37 = 0;
                        int num38 = exprs.Count;
                        while (num37 < num38)
                        {
                            linkArray[num37].Expansion = list11[num37];
                            num37++;
                        }
                    }
                    return(new SqlLink(linkArray[0].Id, linkArray[0].RowType, linkArray[0].ClrType,
                                       linkArray[0].SqlType, linkArray[0].Expression, linkArray[0].Member,
                                       keyExpressions, expansion, linkArray[0].SourceExpression));
                }

                case SqlNodeType.ClientCase:
                {
                    SqlClientCase[] caseArray = new SqlClientCase[exprs.Count];
                    caseArray[0] = (SqlClientCase)exprs[0];
                    for (int i = 1; i < caseArray.Length; i++)
                    {
                        caseArray[i] = (SqlClientCase)exprs[i];
                    }
                    List <SqlExpression> list3 = new List <SqlExpression>();
                    for (int j = 0; j < caseArray.Length; j++)
                    {
                        list3.Add(caseArray[j].Expression);
                    }
                    SqlExpression        expr  = this.ExpandTogether(list3);
                    List <SqlClientWhen> whens = new List <SqlClientWhen>();
                    for (int k = 0; k < caseArray[0].Whens.Count; k++)
                    {
                        List <SqlExpression> list5 = new List <SqlExpression>();
                        for (int m = 0; m < caseArray.Length; m++)
                        {
                            SqlClientWhen when = caseArray[m].Whens[k];
                            list5.Add(when.Value);
                        }
                        whens.Add(new SqlClientWhen(caseArray[0].Whens[k].Match, this.ExpandTogether(list5)));
                    }
                    return(new SqlClientCase(caseArray[0].ClrType, expr, whens, caseArray[0].SourceExpression));
                }

                case SqlNodeType.DiscriminatedType:
                {
                    SqlDiscriminatedType type   = (SqlDiscriminatedType)exprs[0];
                    List <SqlExpression> list15 = new List <SqlExpression>(exprs.Count);
                    list15.Add(type.Discriminator);
                    int num44 = 1;
                    int num45 = exprs.Count;
                    while (num44 < num45)
                    {
                        SqlDiscriminatedType type2 = (SqlDiscriminatedType)exprs[num44];
                        if (type2.TargetType != type.TargetType)
                        {
                            throw Error.UnionIncompatibleConstruction();
                        }
                        list15.Add(type2.Discriminator);
                        num44++;
                    }
                    return(this.factory.DiscriminatedType(this.ExpandTogether(list15),
                                                          ((SqlDiscriminatedType)exprs[0]).TargetType));
                }

                case SqlNodeType.MethodCall:
                {
                    SqlMethodCall[] callArray = new SqlMethodCall[exprs.Count];
                    for (int n = 0; n < callArray.Length; n++)
                    {
                        callArray[n] = (SqlMethodCall)exprs[n];
                    }
                    List <SqlExpression> list = new List <SqlExpression>();
                    for (int num2 = 0; num2 < callArray[0].Arguments.Count; num2++)
                    {
                        List <SqlExpression> list2 = new List <SqlExpression>();
                        for (int num3 = 0; num3 < callArray.Length; num3++)
                        {
                            list2.Add(callArray[num3].Arguments[num2]);
                        }
                        SqlExpression item = this.ExpandTogether(list2);
                        list.Add(item);
                    }
                    return(this.factory.MethodCall(callArray[0].Method, callArray[0].Object, list.ToArray(),
                                                   callArray[0].SourceExpression));
                }

                case SqlNodeType.New:
                {
                    SqlNew[] newArray = new SqlNew[exprs.Count];
                    newArray[0] = (SqlNew)exprs[0];
                    int num13 = 1;
                    int num14 = exprs.Count;
                    while (num13 < num14)
                    {
                        if ((exprs[num13] == null) || (exprs[num13].NodeType != SqlNodeType.New))
                        {
                            throw Error.UnionIncompatibleConstruction();
                        }
                        newArray[num13] = (SqlNew)exprs[1];
                        if (newArray[num13].Members.Count != newArray[0].Members.Count)
                        {
                            throw Error.UnionDifferentMembers();
                        }
                        int num15 = 0;
                        int num16 = newArray[0].Members.Count;
                        while (num15 < num16)
                        {
                            if (newArray[num13].Members[num15].Member != newArray[0].Members[num15].Member)
                            {
                                throw Error.UnionDifferentMemberOrder();
                            }
                            num15++;
                        }
                        num13++;
                    }
                    SqlMemberAssign[] bindings = new SqlMemberAssign[newArray[0].Members.Count];
                    int num17  = 0;
                    int length = bindings.Length;
                    while (num17 < length)
                    {
                        List <SqlExpression> list9 = new List <SqlExpression>();
                        int num19 = 0;
                        int num20 = exprs.Count;
                        while (num19 < num20)
                        {
                            list9.Add(newArray[num19].Members[num17].Expression);
                            num19++;
                        }
                        bindings[num17] = new SqlMemberAssign(newArray[0].Members[num17].Member,
                                                              this.ExpandTogether(list9));
                        int num21 = 0;
                        int num22 = exprs.Count;
                        while (num21 < num22)
                        {
                            newArray[num21].Members[num17].Expression = list9[num21];
                            num21++;
                        }
                        num17++;
                    }
                    SqlExpression[] args  = new SqlExpression[newArray[0].Args.Count];
                    int             num23 = 0;
                    int             num24 = args.Length;
                    while (num23 < num24)
                    {
                        List <SqlExpression> list10 = new List <SqlExpression>();
                        int num25 = 0;
                        int num26 = exprs.Count;
                        while (num25 < num26)
                        {
                            list10.Add(newArray[num25].Args[num23]);
                            num25++;
                        }
                        args[num23] = this.ExpandTogether(list10);
                        num23++;
                    }
                    return(this.factory.New(newArray[0].MetaType, newArray[0].Constructor, args,
                                            newArray[0].ArgMembers, bindings, exprs[0].SourceExpression));
                }

                case SqlNodeType.OptionalValue:
                {
                    if (exprs[0].SqlType.CanBeColumn)
                    {
                        break;
                    }
                    List <SqlExpression> list12 = new List <SqlExpression>(exprs.Count);
                    List <SqlExpression> list13 = new List <SqlExpression>(exprs.Count);
                    int num40 = 0;
                    int num41 = exprs.Count;
                    while (num40 < num41)
                    {
                        if ((exprs[num40] == null) || (exprs[num40].NodeType != SqlNodeType.OptionalValue))
                        {
                            throw Error.UnionIncompatibleConstruction();
                        }
                        SqlOptionalValue value4 = (SqlOptionalValue)exprs[num40];
                        list12.Add(value4.HasValue);
                        list13.Add(value4.Value);
                        num40++;
                    }
                    return(new SqlOptionalValue(this.ExpandTogether(list12), this.ExpandTogether(list13)));
                }

                case SqlNodeType.OuterJoinedValue:
                {
                    if (exprs[0].SqlType.CanBeColumn)
                    {
                        break;
                    }
                    List <SqlExpression> list14 = new List <SqlExpression>(exprs.Count);
                    int num42 = 0;
                    int num43 = exprs.Count;
                    while (num42 < num43)
                    {
                        if ((exprs[num42] == null) || (exprs[num42].NodeType != SqlNodeType.OuterJoinedValue))
                        {
                            throw Error.UnionIncompatibleConstruction();
                        }
                        SqlUnary unary = (SqlUnary)exprs[num42];
                        list14.Add(unary.Operand);
                        num42++;
                    }
                    return(this.factory.Unary(SqlNodeType.OuterJoinedValue, this.ExpandTogether(list14)));
                }

                case SqlNodeType.TypeCase:
                {
                    SqlTypeCase[] caseArray2 = new SqlTypeCase[exprs.Count];
                    caseArray2[0] = (SqlTypeCase)exprs[0];
                    for (int num8 = 1; num8 < caseArray2.Length; num8++)
                    {
                        caseArray2[num8] = (SqlTypeCase)exprs[num8];
                    }
                    List <SqlExpression> list6 = new List <SqlExpression>();
                    for (int num9 = 0; num9 < caseArray2.Length; num9++)
                    {
                        list6.Add(caseArray2[num9].Discriminator);
                    }
                    SqlExpression discriminator = this.ExpandTogether(list6);
                    for (int num10 = 0; num10 < caseArray2.Length; num10++)
                    {
                        caseArray2[num10].Discriminator = list6[num10];
                    }
                    List <SqlTypeCaseWhen> list7 = new List <SqlTypeCaseWhen>();
                    for (int num11 = 0; num11 < caseArray2[0].Whens.Count; num11++)
                    {
                        List <SqlExpression> list8 = new List <SqlExpression>();
                        for (int num12 = 0; num12 < caseArray2.Length; num12++)
                        {
                            SqlTypeCaseWhen when2 = caseArray2[num12].Whens[num11];
                            list8.Add(when2.TypeBinding);
                        }
                        SqlExpression typeBinding = this.ExpandTogether(list8);
                        list7.Add(new SqlTypeCaseWhen(caseArray2[0].Whens[num11].Match, typeBinding));
                    }
                    return(this.factory.TypeCase(caseArray2[0].ClrType, caseArray2[0].RowType, discriminator,
                                                 list7, caseArray2[0].SourceExpression));
                }

                case SqlNodeType.Value:
                {
                    SqlValue value2 = (SqlValue)exprs[0];
                    for (int num39 = 1; num39 < exprs.Count; num39++)
                    {
                        SqlValue value3 = (SqlValue)exprs[num39];
                        if (!object.Equals(value3.Value, value2.Value))
                        {
                            return(this.ExpandIntoExprSet(exprs));
                        }
                    }
                    return(value2);
                }
                }
                return(this.ExpandIntoExprSet(exprs));
            }
Пример #7
0
            private void FlattenGroupByExpression(IList <SqlExpression> exprs, SqlExpression expr)
            {
                SqlNew new2 = expr as SqlNew;

                if (new2 != null)
                {
                    foreach (SqlMemberAssign assign in new2.Members)
                    {
                        this.FlattenGroupByExpression(exprs, assign.Expression);
                    }
                    foreach (SqlExpression expression in new2.Args)
                    {
                        this.FlattenGroupByExpression(exprs, expression);
                    }
                }
                else if (expr.NodeType == SqlNodeType.TypeCase)
                {
                    SqlTypeCase @case = (SqlTypeCase)expr;
                    this.FlattenGroupByExpression(exprs, @case.Discriminator);
                    foreach (SqlTypeCaseWhen when in @case.Whens)
                    {
                        this.FlattenGroupByExpression(exprs, when.TypeBinding);
                    }
                }
                else if (expr.NodeType == SqlNodeType.Link)
                {
                    SqlLink link = (SqlLink)expr;
                    if (link.Expansion != null)
                    {
                        this.FlattenGroupByExpression(exprs, link.Expansion);
                    }
                    else
                    {
                        foreach (SqlExpression expression2 in link.KeyExpressions)
                        {
                            this.FlattenGroupByExpression(exprs, expression2);
                        }
                    }
                }
                else if (expr.NodeType == SqlNodeType.OptionalValue)
                {
                    SqlOptionalValue value2 = (SqlOptionalValue)expr;
                    this.FlattenGroupByExpression(exprs, value2.HasValue);
                    this.FlattenGroupByExpression(exprs, value2.Value);
                }
                else if (expr.NodeType == SqlNodeType.OuterJoinedValue)
                {
                    this.FlattenGroupByExpression(exprs, ((SqlUnary)expr).Operand);
                }
                else if (expr.NodeType == SqlNodeType.DiscriminatedType)
                {
                    SqlDiscriminatedType type = (SqlDiscriminatedType)expr;
                    this.FlattenGroupByExpression(exprs, type.Discriminator);
                }
                else
                {
                    if ((expr.NodeType != SqlNodeType.ColumnRef) && (expr.NodeType != SqlNodeType.ExprSet))
                    {
                        if (!expr.SqlType.CanBeColumn)
                        {
                            throw Error.InvalidGroupByExpressionType(expr.SqlType.ToQueryString());
                        }
                        throw Error.InvalidGroupByExpression();
                    }
                    exprs.Add(expr);
                }
            }