internal GroupPartitionInfo( GroupPartitionExpr groupPartitionExpr, ErrorContext errCtx, GroupAggregateInfo containingAggregate, ScopeRegion definingScopeRegion) : base(GroupAggregateKind.Partition, groupPartitionExpr, errCtx, containingAggregate, definingScopeRegion) { Debug.Assert(groupPartitionExpr != null, "groupPartitionExpr != null"); }
/// <summary> /// Reports incompatible type error /// </summary> /// <param name="errCtx"></param> /// <param name="leftType"></param> /// <param name="rightType"></param> internal static void ReportIncompatibleCommonType( ErrorContext errCtx, TypeUsage leftType, TypeUsage rightType ) { // // 'navigate' through the type structure in order to find where the incompability is // ReportIncompatibleCommonType(errCtx, leftType, rightType, leftType, rightType); // // if we hit this point, throw the generic incompatible type error message // throw EntityUtil.EntitySqlError(errCtx, System.Data.Entity.Strings.ArgumentTypesAreIncompatible(leftType.Identity, rightType.Identity)); }
protected GroupAggregateInfo( GroupAggregateKind aggregateKind, GroupAggregateExpr astNode, ErrorContext errCtx, GroupAggregateInfo containingAggregate, ScopeRegion definingScopeRegion) { Debug.Assert(aggregateKind != GroupAggregateKind.None, "aggregateKind != GroupAggregateKind.None"); Debug.Assert(errCtx != null, "errCtx != null"); Debug.Assert(definingScopeRegion != null, "definingScopeRegion != null"); AggregateKind = aggregateKind; AstNode = astNode; ErrCtx = errCtx; DefiningScopeRegion = definingScopeRegion; SetContainingAggregate(containingAggregate); }
/// <summary> /// Initializes a new instance EntityException with an ErrorContext instance and a given error message. /// </summary> internal static EntitySqlException Create(ErrorContext errCtx, string errorMessage, Exception innerException) { return EntitySqlException.Create(errCtx.CommandText, errorMessage, errCtx.InputPosition, errCtx.ErrorContextInfo, errCtx.UseContextInfoAsResourceIdentifier, innerException); }
/// <summary> /// Adds an aliased namespace import. /// </summary> internal void AddAliasedNamespaceImport(string alias, MetadataNamespace @namespace, ErrorContext errCtx) { if (_aliasedNamespaces.ContainsKey(alias)) { throw EntityUtil.EntitySqlError(errCtx, Strings.NamespaceAliasAlreadyUsed(alias)); } _aliasedNamespaces.Add(alias, @namespace); }
internal MetadataMember ResolveUnqualifiedName(string name, bool partOfQualifiedName, ErrorContext errCtx) { Debug.Assert(!String.IsNullOrEmpty(name), "name must not be empty"); // // In the case of Name1.Name2...NameN and if backward compatibility mode is on, then resolve Name1 as namespace only, ignore any other possible resolutions. // bool resolveAsNamespaceOnly = partOfQualifiedName && _resolveLeftMostUnqualifiedNameAsNamespaceOnly; // // In the case of Name1.Name2...NameN, ignore functions while resolving Name1: functions don't have members. // bool includeFunctions = !partOfQualifiedName; // // Try resolving as an inline function. // InlineFunctionGroup inlineFunctionGroup; if (!resolveAsNamespaceOnly && includeFunctions && TryGetInlineFunction(name, out inlineFunctionGroup)) { return(inlineFunctionGroup); } // // Try resolving as a namespace alias. // MetadataNamespace aliasedNamespaceImport; if (_aliasedNamespaces.TryGetValue(name, out aliasedNamespaceImport)) { return(aliasedNamespaceImport); } if (!resolveAsNamespaceOnly) { // // Try resolving as a type or functionGroup in the global namespace or as an imported member. // Throw if ambiguous. // MetadataType type = null; MetadataFunctionGroup functionGroup = null; if (!TryGetTypeFromMetadata(name, out type)) { if (includeFunctions) { // // If name looks like a multipart identifier, try resolving it in the global namespace. // Escaped multipart identifiers usually appear in views: select [NS1.NS2.Product](...) from ... // var multipart = name.Split('.'); if (multipart.Length > 1 && multipart.All(p => p.Length > 0)) { var functionName = multipart[multipart.Length - 1]; var namespaceName = name.Substring(0, name.Length - functionName.Length - 1); TryGetFunctionFromMetadata(namespaceName, functionName, out functionGroup); } } } // // Try resolving as an imported member. // MetadataNamespace importedMemberNamespace = null; foreach (MetadataNamespace namespaceImport in _namespaces) { string fullName = GetFullName(namespaceImport.Name, name); MetadataType importedType; if (TryGetTypeFromMetadata(fullName, out importedType)) { if (type == null && functionGroup == null) { type = importedType; importedMemberNamespace = namespaceImport; } else { throw AmbiguousMetadataMemberName(errCtx, name, namespaceImport, importedMemberNamespace); } } MetadataFunctionGroup importedFunctionGroup; if (includeFunctions && TryGetFunctionFromMetadata(namespaceImport.Name, name, out importedFunctionGroup)) { if (type == null && functionGroup == null) { functionGroup = importedFunctionGroup; importedMemberNamespace = namespaceImport; } else { throw AmbiguousMetadataMemberName(errCtx, name, namespaceImport, importedMemberNamespace); } } } if (type != null) { return(type); } if (functionGroup != null) { return(functionGroup); } } // // Otherwise, resolve as a namespace. // return(new MetadataNamespace(name)); }
/// <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; } }
internal static void ReportAliasAlreadyUsedError(string aliasName, ErrorContext errCtx, string contextMessage) { throw EntitySqlException.Create( errCtx, String.Format(CultureInfo.InvariantCulture, "{0} {1}", Strings.AliasNameAlreadyUsed(aliasName), contextMessage), null); }
/// <summary> /// provides error feedback for aliases already used in a given context /// </summary> /// <param name="aliasName"></param> /// <param name="errCtx"></param> /// <param name="contextMessage"></param> internal static void ReportAliasAlreadyUsedError( string aliasName, ErrorContext errCtx, string contextMessage ) { throw EntityUtil.EntitySqlError(errCtx, String.Format(CultureInfo.InvariantCulture, "{0} {1}", System.Data.Entity.Strings.AliasNameAlreadyUsed(aliasName), contextMessage)); }
internal FunctionAggregateInfo( MethodExpr methodExpr, ErrorContext errCtx, GroupAggregateInfo containingAggregate, ScopeRegion definingScopeRegion) : base(GroupAggregateKind.Function, methodExpr, errCtx, containingAggregate, definingScopeRegion) { Debug.Assert(methodExpr != null, "methodExpr != null"); }
internal override DbExpression GetExpression(string refName, ErrorContext errCtx) { return _varBasedExpression; }
/// <summary> /// Returns CQT expression corresponding to the scope entry. /// </summary> internal abstract DbExpression GetExpression(string refName, ErrorContext errCtx);
internal MetadataMember ResolveMetadataMemberAccess(MetadataMember qualifier, string name, ErrorContext errCtx) { string fullName = GetFullName(qualifier.Name, name); if (qualifier.MetadataMemberClass == MetadataMemberClass.Namespace) { // // Try resolving as a type. // MetadataType type; if (TryGetTypeFromMetadata(fullName, out type)) { return(type); } // // Try resolving as a function. // MetadataFunctionGroup function; if (TryGetFunctionFromMetadata(qualifier.Name, name, out function)) { return(function); } // // Otherwise, resolve as a namespace. // return(new MetadataNamespace(fullName)); } else if (qualifier.MetadataMemberClass == MetadataMemberClass.Type) { var type = (MetadataType)qualifier; if (TypeSemantics.IsEnumerationType(type.TypeUsage)) { EnumMember member; if (_perspective.TryGetEnumMember((EnumType)type.TypeUsage.EdmType, name, _parserOptions.NameComparisonCaseInsensitive /*ignoreCase*/, out member)) { Debug.Assert(member != null, "member != null"); Debug.Assert(_parserOptions.NameComparer.Equals(name, member.Name), "_parserOptions.NameComparer.Equals(name, member.Name)"); return(new MetadataEnumMember(fullName, type.TypeUsage, member)); } else { throw EntityUtil.EntitySqlError(errCtx, Strings.NotAMemberOfType(name, qualifier.Name)); } } } throw EntityUtil.EntitySqlError(errCtx, Strings.InvalidMetadataMemberClassResolution( qualifier.Name, qualifier.MetadataMemberClassName, MetadataNamespace.NamespaceClassName)); }
internal override DbExpression GetExpression(string refName, ErrorContext errCtx) { var message = Strings.InvalidGroupIdentifierReference(refName); throw EntitySqlException.Create(errCtx, message, null); }
internal override DbExpression GetExpression(string refName, ErrorContext errCtx) { return(_varRef); }
internal override DbExpression GetExpression(string refName, ErrorContext errCtx) { throw EntityUtil.EntitySqlError(errCtx, Strings.InvalidGroupIdentifierReference(refName)); }
private static Exception AmbiguousMetadataMemberName(ErrorContext errCtx, string name, MetadataNamespace ns1, MetadataNamespace ns2) { throw EntityUtil.EntitySqlError(errCtx, Strings.AmbiguousMetadataMemberName(name, ns1.Name, ns2 != null ? ns2.Name : null)); }