/// <summary>
        /// navigates through the type structure to find where the incompatibility happens
        /// </summary>
        /// <param name="errCtx"></param>
        /// <param name="rootLeftType"></param>
        /// <param name="rootRightType"></param>
        /// <param name="leftType"></param>
        /// <param name="rightType"></param>
        private static void ReportIncompatibleCommonType(ErrorContext errCtx, TypeUsage rootLeftType, TypeUsage rootRightType, TypeUsage leftType, TypeUsage rightType)
        {
            TypeUsage commonType   = null;
            bool      isRootType   = (rootLeftType == leftType);
            string    errorMessage = String.Empty;

            if (leftType.EdmType.BuiltInTypeKind != rightType.EdmType.BuiltInTypeKind)
            {
                throw EntityUtil.EntitySqlError(errCtx,
                                                System.Data.Entity.Strings.TypeKindMismatch(
                                                    GetReadableTypeKind(leftType),
                                                    GetReadableTypeName(leftType),
                                                    GetReadableTypeKind(rightType),
                                                    GetReadableTypeName(rightType)));
            }

            switch (leftType.EdmType.BuiltInTypeKind)
            {
            case BuiltInTypeKind.RowType:
                RowType leftRow  = (RowType)leftType.EdmType;
                RowType rightRow = (RowType)rightType.EdmType;

                if (leftRow.Members.Count != rightRow.Members.Count)
                {
                    if (isRootType)
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidRootRowType(
                            GetReadableTypeName(leftRow),
                            GetReadableTypeName(rightRow));
                    }
                    else
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidRowType(
                            GetReadableTypeName(leftRow),
                            GetReadableTypeName(rootLeftType),
                            GetReadableTypeName(rightRow),
                            GetReadableTypeName(rootRightType));
                    }

                    throw EntityUtil.EntitySqlError(errCtx, errorMessage);
                }

                for (int i = 0; i < leftRow.Members.Count; i++)
                {
                    ReportIncompatibleCommonType(errCtx, rootLeftType, rootRightType, leftRow.Members[i].TypeUsage, rightRow.Members[i].TypeUsage);
                }
                break;

            case BuiltInTypeKind.CollectionType:
            case BuiltInTypeKind.RefType:
                ReportIncompatibleCommonType(errCtx,
                                             rootLeftType,
                                             rootRightType,
                                             TypeHelpers.GetElementTypeUsage(leftType),
                                             TypeHelpers.GetElementTypeUsage(rightType));
                break;

            case BuiltInTypeKind.EntityType:
                if (!TypeSemantics.TryGetCommonType(leftType, rightType, out commonType))
                {
                    if (isRootType)
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidEntityRootTypeArgument(
                            GetReadableTypeName(leftType),
                            GetReadableTypeName(rightType));
                    }
                    else
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidEntityTypeArgument(
                            GetReadableTypeName(leftType),
                            GetReadableTypeName(rootLeftType),
                            GetReadableTypeName(rightType),
                            GetReadableTypeName(rootRightType));
                    }
                    throw EntityUtil.EntitySqlError(errCtx, errorMessage);
                }
                break;

            case BuiltInTypeKind.ComplexType:
                ComplexType leftComplex  = (ComplexType)leftType.EdmType;
                ComplexType rightComplex = (ComplexType)rightType.EdmType;
                if (leftComplex.Members.Count != rightComplex.Members.Count)
                {
                    if (isRootType)
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidRootComplexType(
                            GetReadableTypeName(leftComplex),
                            GetReadableTypeName(rightComplex));
                    }
                    else
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidComplexType(
                            GetReadableTypeName(leftComplex),
                            GetReadableTypeName(rootLeftType),
                            GetReadableTypeName(rightComplex),
                            GetReadableTypeName(rootRightType));
                    }
                    throw EntityUtil.EntitySqlError(errCtx, errorMessage);
                }

                for (int i = 0; i < leftComplex.Members.Count; i++)
                {
                    ReportIncompatibleCommonType(errCtx,
                                                 rootLeftType,
                                                 rootRightType,
                                                 leftComplex.Members[i].TypeUsage,
                                                 rightComplex.Members[i].TypeUsage);
                }
                break;

            default:
                if (!TypeSemantics.TryGetCommonType(leftType, rightType, out commonType))
                {
                    if (isRootType)
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidPlaceholderRootTypeArgument(
                            GetReadableTypeKind(leftType),
                            GetReadableTypeName(leftType),
                            GetReadableTypeKind(rightType),
                            GetReadableTypeName(rightType));
                    }
                    else
                    {
                        errorMessage = System.Data.Entity.Strings.InvalidPlaceholderTypeArgument(
                            GetReadableTypeKind(leftType),
                            GetReadableTypeName(leftType),
                            GetReadableTypeName(rootLeftType),
                            GetReadableTypeKind(rightType),
                            GetReadableTypeName(rightType),
                            GetReadableTypeName(rootRightType));
                    }
                    throw EntityUtil.EntitySqlError(errCtx, errorMessage);
                }
                break;
            }
        }
Example #2
0
        private static void ReportIncompatibleCommonType(
            ErrorContext errCtx,
            TypeUsage rootLeftType,
            TypeUsage rootRightType,
            TypeUsage leftType,
            TypeUsage rightType)
        {
            TypeUsage commonType = (TypeUsage)null;
            bool      flag       = rootLeftType == leftType;
            string    empty      = string.Empty;

            if (leftType.EdmType.BuiltInTypeKind != rightType.EdmType.BuiltInTypeKind)
            {
                throw EntitySqlException.Create(errCtx, Strings.TypeKindMismatch((object)CqlErrorHelper.GetReadableTypeKind(leftType), (object)CqlErrorHelper.GetReadableTypeName(leftType), (object)CqlErrorHelper.GetReadableTypeKind(rightType), (object)CqlErrorHelper.GetReadableTypeName(rightType)), (Exception)null);
            }
            switch (leftType.EdmType.BuiltInTypeKind)
            {
            case BuiltInTypeKind.CollectionType:
            case BuiltInTypeKind.RefType:
                CqlErrorHelper.ReportIncompatibleCommonType(errCtx, rootLeftType, rootRightType, TypeHelpers.GetElementTypeUsage(leftType), TypeHelpers.GetElementTypeUsage(rightType));
                break;

            case BuiltInTypeKind.ComplexType:
                ComplexType edmType1 = (ComplexType)leftType.EdmType;
                ComplexType edmType2 = (ComplexType)rightType.EdmType;
                if (edmType1.Members.Count != edmType2.Members.Count)
                {
                    string errorMessage = !flag?Strings.InvalidComplexType((object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType1), (object)CqlErrorHelper.GetReadableTypeName(rootLeftType), (object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType2), (object)CqlErrorHelper.GetReadableTypeName(rootRightType)) : Strings.InvalidRootComplexType((object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType1), (object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType2));

                    throw EntitySqlException.Create(errCtx, errorMessage, (Exception)null);
                }
                for (int index = 0; index < edmType1.Members.Count; ++index)
                {
                    CqlErrorHelper.ReportIncompatibleCommonType(errCtx, rootLeftType, rootRightType, edmType1.Members[index].TypeUsage, edmType2.Members[index].TypeUsage);
                }
                break;

            case BuiltInTypeKind.EntityType:
                if (TypeSemantics.TryGetCommonType(leftType, rightType, out commonType))
                {
                    break;
                }
                string errorMessage1 = !flag?Strings.InvalidEntityTypeArgument((object)CqlErrorHelper.GetReadableTypeName(leftType), (object)CqlErrorHelper.GetReadableTypeName(rootLeftType), (object)CqlErrorHelper.GetReadableTypeName(rightType), (object)CqlErrorHelper.GetReadableTypeName(rootRightType)) : Strings.InvalidEntityRootTypeArgument((object)CqlErrorHelper.GetReadableTypeName(leftType), (object)CqlErrorHelper.GetReadableTypeName(rightType));

                throw EntitySqlException.Create(errCtx, errorMessage1, (Exception)null);

            case BuiltInTypeKind.RowType:
                RowType edmType3 = (RowType)leftType.EdmType;
                RowType edmType4 = (RowType)rightType.EdmType;
                if (edmType3.Members.Count != edmType4.Members.Count)
                {
                    string errorMessage2 = !flag?Strings.InvalidRowType((object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType3), (object)CqlErrorHelper.GetReadableTypeName(rootLeftType), (object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType4), (object)CqlErrorHelper.GetReadableTypeName(rootRightType)) : Strings.InvalidRootRowType((object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType3), (object)CqlErrorHelper.GetReadableTypeName((EdmType)edmType4));

                    throw EntitySqlException.Create(errCtx, errorMessage2, (Exception)null);
                }
                for (int index = 0; index < edmType3.Members.Count; ++index)
                {
                    CqlErrorHelper.ReportIncompatibleCommonType(errCtx, rootLeftType, rootRightType, edmType3.Members[index].TypeUsage, edmType4.Members[index].TypeUsage);
                }
                break;

            default:
                if (TypeSemantics.TryGetCommonType(leftType, rightType, out commonType))
                {
                    break;
                }
                string errorMessage3 = !flag?Strings.InvalidPlaceholderTypeArgument((object)CqlErrorHelper.GetReadableTypeKind(leftType), (object)CqlErrorHelper.GetReadableTypeName(leftType), (object)CqlErrorHelper.GetReadableTypeName(rootLeftType), (object)CqlErrorHelper.GetReadableTypeKind(rightType), (object)CqlErrorHelper.GetReadableTypeName(rightType), (object)CqlErrorHelper.GetReadableTypeName(rootRightType)) : Strings.InvalidPlaceholderRootTypeArgument((object)CqlErrorHelper.GetReadableTypeKind(leftType), (object)CqlErrorHelper.GetReadableTypeName(leftType), (object)CqlErrorHelper.GetReadableTypeKind(rightType), (object)CqlErrorHelper.GetReadableTypeName(rightType));

                throw EntitySqlException.Create(errCtx, errorMessage3, (Exception)null);
            }
        }