Beispiel #1
0
        internal static TypeUsage GetElementTypeUsage(TypeUsage type)
        {
            if (TypeSemantics.IsCollectionType(type))
            {
                return(((CollectionType)type.EdmType).TypeUsage);
            }
            else if (TypeSemantics.IsReferenceType(type))
            {
                return(TypeUsage.Create(((RefType)type.EdmType).ElementType));
            }

            return(null);
        }
Beispiel #2
0
        private static TypeUsage CreateResultType(RelationshipEndMember end)
        {
            TypeUsage typeUsage = end.TypeUsage;

            if (!TypeSemantics.IsReferenceType(typeUsage))
            {
                typeUsage = TypeHelpers.CreateReferenceTypeUsage(TypeHelpers.GetEdmType <EntityType>(typeUsage));
            }
            if (RelationshipMultiplicity.Many == end.RelationshipMultiplicity)
            {
                typeUsage = TypeHelpers.CreateCollectionTypeUsage(typeUsage);
            }
            return(typeUsage);
        }
            internal static DbExpression FindNavigationExpression(
                DbExpression expression,
                AliasGenerator aliasGenerator,
                out ObjectSpanRewriter.NavigationInfo navInfo)
            {
                navInfo = (ObjectSpanRewriter.NavigationInfo)null;
                TypeUsage typeUsage = ((CollectionType)expression.ResultType.EdmType).TypeUsage;

                if (!TypeSemantics.IsEntityType(typeUsage) && !TypeSemantics.IsReferenceType(typeUsage))
                {
                    return(expression);
                }
                ObjectSpanRewriter.RelationshipNavigationVisitor navigationVisitor = new ObjectSpanRewriter.RelationshipNavigationVisitor(aliasGenerator);
                DbExpression dbExpression = navigationVisitor.Find(expression);

                if (object.ReferenceEquals((object)expression, (object)dbExpression))
                {
                    return(expression);
                }
                navInfo = new ObjectSpanRewriter.NavigationInfo(navigationVisitor._original, navigationVisitor._rewritten);
                return(dbExpression);
            }
Beispiel #4
0
        public override void Visit(SoftCastOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            PropertyRefList propertyRefs = (PropertyRefList)null;

            if (TypeSemantics.IsReferenceType(op.Type))
            {
                propertyRefs = PropertyRefList.All;
            }
            else if (TypeSemantics.IsNominalType(op.Type))
            {
                propertyRefs = this.m_nodePropertyRefMap[n].Clone();
            }
            else if (TypeSemantics.IsRowType(op.Type))
            {
                propertyRefs = PropertyRefList.All;
            }
            if (propertyRefs != null)
            {
                this.AddPropertyRefs(n.Child0, propertyRefs);
            }
            this.VisitChildren(n);
        }
Beispiel #5
0
        private bool TryResolveAsRefPropertyAccess(
            DbExpression valueExpr,
            string name,
            ErrorContext errCtx,
            out DbExpression propertyExpr)
        {
            propertyExpr = (DbExpression)null;
            if (!TypeSemantics.IsReferenceType(valueExpr.ResultType))
            {
                return(false);
            }
            DbExpression valueExpr1 = (DbExpression)valueExpr.Deref();
            TypeUsage    resultType = valueExpr1.ResultType;

            if (this.TryResolveAsPropertyAccess(valueExpr1, name, out propertyExpr))
            {
                return(true);
            }
            string errorMessage = Strings.InvalidDeRefProperty((object)name, (object)resultType.EdmType.FullName, (object)valueExpr.ResultType.EdmType.FullName);

            throw EntitySqlException.Create(errCtx, errorMessage, (Exception)null);
        }
Beispiel #6
0
        public override void Visit(ComparisonOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            TypeUsage type = (n.Child0.Op as ScalarOp).Type;

            if (!TypeUtils.IsStructuredType(type))
            {
                this.VisitChildren(n);
            }
            else if (TypeSemantics.IsRowType(type) || TypeSemantics.IsReferenceType(type))
            {
                this.VisitDefault(n);
            }
            else
            {
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(TypeSemantics.IsEntityType(type), "unexpected childOpType?");
                PropertyRefList identityProperties = PropertyPushdownHelper.GetIdentityProperties(TypeHelpers.GetEdmType <EntityType>(type));
                foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in n.Children)
                {
                    this.AddPropertyRefs(child, identityProperties);
                }
                this.VisitChildren(n);
            }
        }
Beispiel #7
0
        private static void RequireCompatibleType(
            DbExpression from,
            RelationshipEndMember end,
            bool allowAllRelationshipsInSameTypeHierarchy)
        {
            TypeUsage typeUsage = end.TypeUsage;

            if (!TypeSemantics.IsReferenceType(typeUsage))
            {
                typeUsage = TypeHelpers.CreateReferenceTypeUsage(TypeHelpers.GetEdmType <EntityType>(typeUsage));
            }
            if (allowAllRelationshipsInSameTypeHierarchy)
            {
                if (TypeHelpers.GetCommonTypeUsage(typeUsage, from.ResultType) == null)
                {
                    throw new ArgumentException(Strings.Cqt_RelNav_WrongSourceType((object)typeUsage.ToString()), nameof(from));
                }
            }
            else if (!TypeSemantics.IsStructurallyEqualOrPromotableTo(from.ResultType.EdmType, typeUsage.EdmType))
            {
                throw new ArgumentException(Strings.Cqt_RelNav_WrongSourceType((object)typeUsage.ToString()), nameof(from));
            }
        }
        /// <summary>
        ///     If <paramref name="valueExpr" /> returns a reference, then deref and try resolving <paramref name="name" /> as a property of the dereferenced value.
        /// </summary>
        private bool TryResolveAsRefPropertyAccess(DbExpression valueExpr, string name, ErrorContext errCtx, out DbExpression propertyExpr)
        {
            DebugCheck.NotNull(valueExpr);

            propertyExpr = null;

            if (TypeSemantics.IsReferenceType(valueExpr.ResultType))
            {
                DbExpression derefExpr     = valueExpr.Deref();
                var          derefExprType = derefExpr.ResultType;

                if (TryResolveAsPropertyAccess(derefExpr, name, out propertyExpr))
                {
                    return(true);
                }
                else
                {
                    var message = Strings.InvalidDeRefProperty(name, derefExprType.EdmType.FullName, valueExpr.ResultType.EdmType.FullName);
                    throw EntitySqlException.Create(errCtx, message, null);
                }
            }

            return(false);
        }
 internal DbEntityRefExpression(TypeUsage refResultType, DbExpression entity)
     : base(DbExpressionKind.EntityRef, refResultType, entity)
 {
     Debug.Assert(TypeSemantics.IsReferenceType(refResultType), "DbEntityRefExpression requires a reference result type");
 }
Beispiel #10
0
        internal static Type GetClrTypeFromTypeMetadata(TypeUsage typeUsage)
        {
            PrimitiveType type;

            return(!TypeHelpers.TryGetEdmType <PrimitiveType>(typeUsage, out type) ? (!TypeSemantics.IsReferenceType(typeUsage) ? (!TypeUtils.IsStructuredType(typeUsage) ? (!TypeUtils.IsCollectionType(typeUsage) ? (!TypeUtils.IsEnumerationType(typeUsage) ? typeof(object) : ((EnumType)typeUsage.EdmType).UnderlyingType.ClrEquivalentType) : typeof(DbDataReader)) : typeof(DbDataRecord)) : typeof(EntityKey)) : type.ClrEquivalentType);
        }
Beispiel #11
0
 internal static bool IsValidInOpType(TypeUsage typeUsage)
 {
     return(TypeSemantics.IsReferenceType(typeUsage) ||
            TypeSemantics.IsEntityType(typeUsage) ||
            TypeSemantics.IsScalarType(typeUsage));
 }