private bool IsDisjoint(CellTreeNode n1, CellTreeNode n2)
        {
            int  viewTarget = (int)this.m_viewgenContext.ViewTarget;
            bool flag       = this.LeftQP.IsDisjointFrom(n1.LeftFragmentQuery, n2.LeftFragmentQuery);

            if (flag && this.m_viewgenContext.ViewTarget == ViewTarget.QueryView)
            {
                return(true);
            }
            bool rightFragmentQuery = new OpCellTreeNode(this.m_viewgenContext, CellTreeOpType.IJ, new CellTreeNode[2]
            {
                n1,
                n2
            }).IsEmptyRightFragmentQuery;

            if (this.m_viewgenContext.ViewTarget == ViewTarget.UpdateView && flag && !rightFragmentQuery)
            {
                if (ErrorPatternMatcher.FindMappingErrors(this.m_viewgenContext, this.m_domainMap, this.m_errorLog))
                {
                    return(false);
                }
                StringBuilder builder = new StringBuilder(Strings.Viewgen_RightSideNotDisjoint((object)this.m_viewgenContext.Extent.ToString()));
                builder.AppendLine();
                FragmentQuery query = this.LeftQP.Intersect(n1.RightFragmentQuery, n2.RightFragmentQuery);
                if (this.LeftQP.IsSatisfiable(query))
                {
                    query.Condition.ExpensiveSimplify();
                    RewritingValidator.EntityConfigurationToUserString(query.Condition, builder);
                }
                this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.DisjointConstraintViolation, builder.ToString(), (IEnumerable <LeftCellWrapper>) this.m_viewgenContext.AllWrappersForExtent, string.Empty));
                ExceptionHelpers.ThrowMappingException(this.m_errorLog, this.m_config);
                return(false);
            }
            if (!flag)
            {
                return(rightFragmentQuery);
            }
            return(true);
        }
        private void GenerateCaseStatements(
            IEnumerable <MemberPath> members,
            HashSet <FragmentQuery> outputUsedViews)
        {
            CellTreeNode rightDomainQuery = (CellTreeNode) new OpCellTreeNode(this._context, CellTreeOpType.Union, (CellTreeNode[])this._context.AllWrappersForExtent.Where <LeftCellWrapper>((Func <LeftCellWrapper, bool>)(w => this._usedViews.Contains(w.FragmentQuery))).Select <LeftCellWrapper, LeafCellTreeNode>((Func <LeftCellWrapper, LeafCellTreeNode>)(wrapper => new LeafCellTreeNode(this._context, wrapper))).ToArray <LeafCellTreeNode>());

            foreach (MemberPath member in members)
            {
                List <Constant>      list          = this.GetDomain(member).ToList <Constant>();
                CaseStatement        caseStatement = new CaseStatement(member);
                Tile <FragmentQuery> tile          = (Tile <FragmentQuery>)null;
                bool flag = list.Count != 2 || !list.Contains <Constant>(Constant.Null, Constant.EqualityComparer) || !list.Contains <Constant>(Constant.NotNull, Constant.EqualityComparer);
                foreach (Constant domainValue in list)
                {
                    if (domainValue == Constant.Undefined && this._context.ViewTarget == ViewTarget.QueryView)
                    {
                        caseStatement.AddWhenThen(BoolExpression.False, (ProjectedSlot) new ConstantProjectedSlot(Constant.Undefined));
                    }
                    else
                    {
                        FragmentQuery        memberConditionQuery = this.CreateMemberConditionQuery(member, domainValue);
                        Tile <FragmentQuery> rewriting;
                        if (this.FindRewritingAndUsedViews((IEnumerable <MemberPath>)memberConditionQuery.Attributes, memberConditionQuery.Condition, outputUsedViews, out rewriting))
                        {
                            if (this._context.ViewTarget == ViewTarget.UpdateView)
                            {
                                tile = tile != null?this._qp.Union(tile, rewriting) : rewriting;
                            }
                            if (flag)
                            {
                                if (this.AddRewritingToCaseStatement(rewriting, caseStatement, member, domainValue))
                                {
                                    break;
                                }
                            }
                        }
                        else if (!QueryRewriter.IsDefaultValue(domainValue, member) && !ErrorPatternMatcher.FindMappingErrors(this._context, this._domainMap, this._errorLog))
                        {
                            StringBuilder builder = new StringBuilder();
                            string        str1    = StringUtil.FormatInvariant("{0}", (object)this._extentPath);
                            string        str2    = this._context.ViewTarget == ViewTarget.QueryView ? Strings.ViewGen_Entities : Strings.ViewGen_Tuples;
                            if (this._context.ViewTarget == ViewTarget.QueryView)
                            {
                                builder.AppendLine(Strings.Viewgen_CannotGenerateQueryViewUnderNoValidation((object)str1));
                            }
                            else
                            {
                                builder.AppendLine(Strings.ViewGen_Cannot_Disambiguate_MultiConstant((object)str2, (object)str1));
                            }
                            RewritingValidator.EntityConfigurationToUserString(memberConditionQuery.Condition, builder, this._context.ViewTarget == ViewTarget.UpdateView);
                            this._errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.AmbiguousMultiConstants, builder.ToString(), (IEnumerable <LeftCellWrapper>) this._context.AllWrappersForExtent, string.Empty));
                        }
                    }
                }
                if (this._errorLog.Count == 0)
                {
                    if (this._context.ViewTarget == ViewTarget.UpdateView && flag)
                    {
                        this.AddElseDefaultToCaseStatement(member, caseStatement, list, rightDomainQuery, tile);
                    }
                    if (caseStatement.Clauses.Count > 0)
                    {
                        this._caseStatements[member] = caseStatement;
                    }
                }
            }
        }
 private void EnsureConfigurationIsFullyMapped(
     MemberPath currentPath,
     BoolExpression currentWhereClause,
     HashSet <FragmentQuery> outputUsedViews,
     ErrorLog errorLog)
 {
     foreach (Constant domainValue in this.GetDomain(currentPath))
     {
         if (domainValue != Constant.Undefined)
         {
             BoolExpression       memberCondition = this.CreateMemberCondition(currentPath, domainValue);
             BoolExpression       and             = BoolExpression.CreateAnd(currentWhereClause, memberCondition);
             Tile <FragmentQuery> rewriting;
             if (!this.FindRewritingAndUsedViews((IEnumerable <MemberPath>) this._keyAttributes, and, outputUsedViews, out rewriting))
             {
                 if (!ErrorPatternMatcher.FindMappingErrors(this._context, this._domainMap, this._errorLog))
                 {
                     StringBuilder  builder   = new StringBuilder();
                     string         str       = StringUtil.FormatInvariant("{0}", (object)this._extentPath);
                     BoolExpression condition = rewriting.Query.Condition;
                     condition.ExpensiveSimplify();
                     if (condition.RepresentsAllTypeConditions)
                     {
                         string viewGenExtent = Strings.ViewGen_Extent;
                         builder.AppendLine(Strings.ViewGen_Cannot_Recover_Types((object)viewGenExtent, (object)str));
                     }
                     else
                     {
                         string viewGenEntities = Strings.ViewGen_Entities;
                         builder.AppendLine(Strings.ViewGen_Cannot_Disambiguate_MultiConstant((object)viewGenEntities, (object)str));
                     }
                     RewritingValidator.EntityConfigurationToUserString(condition, builder);
                     ErrorLog.Record record = new ErrorLog.Record(ViewGenErrorCode.AmbiguousMultiConstants, builder.ToString(), (IEnumerable <LeftCellWrapper>) this._context.AllWrappersForExtent, string.Empty);
                     errorLog.AddEntry(record);
                 }
             }
             else
             {
                 TypeConstant typeConstant = domainValue as TypeConstant;
                 if (typeConstant != null)
                 {
                     EdmType                  edmType = typeConstant.EdmType;
                     List <MemberPath>        list    = QueryRewriter.GetNonConditionalScalarMembers(edmType, currentPath, this._domainMap).Union <MemberPath>(QueryRewriter.GetNonConditionalComplexMembers(edmType, currentPath, this._domainMap)).ToList <MemberPath>();
                     IEnumerable <MemberPath> notCoveredAttributes;
                     if (list.Count > 0 && !this.FindRewritingAndUsedViews((IEnumerable <MemberPath>)list, and, outputUsedViews, out rewriting, out notCoveredAttributes))
                     {
                         List <MemberPath> memberPathList = new List <MemberPath>(list.Where <MemberPath>((Func <MemberPath, bool>)(a => !a.IsPartOfKey)));
                         this.AddUnrecoverableAttributesError(notCoveredAttributes, memberCondition, errorLog);
                     }
                     else
                     {
                         foreach (MemberPath conditionalComplexMember in QueryRewriter.GetConditionalComplexMembers(edmType, currentPath, this._domainMap))
                         {
                             this.EnsureConfigurationIsFullyMapped(conditionalComplexMember, and, outputUsedViews, errorLog);
                         }
                         foreach (MemberPath conditionalScalarMember in QueryRewriter.GetConditionalScalarMembers(edmType, currentPath, this._domainMap))
                         {
                             this.EnsureConfigurationIsFullyMapped(conditionalScalarMember, and, outputUsedViews, errorLog);
                         }
                     }
                 }
             }
         }
     }
 }