Exemple #1
0
        /// <summary>
        /// Tries to lookup custom discriminator map for the given type (applies to EntitySets with
        /// TPH discrimination pattern)
        /// </summary>
        private bool TryGetDiscriminatorMap(md.EdmType type, out ExplicitDiscriminatorMap discriminatorMap)
        {
            discriminatorMap = null;

            // check that there are actually discriminator maps available
            if (null == m_discriminatorMaps)
            {
                return(false);
            }

            // must be an entity type...
            if (type.BuiltInTypeKind != md.BuiltInTypeKind.EntityType)
            {
                return(false);
            }

            // get root entity type (discriminator maps are mapped from the root)
            md.EntityTypeBase rootEntityType = GetRootType((md.EntityType)type);

            // find entity set
            md.EntitySet entitySet;
            if (!m_entityTypeToEntitySetMap.TryGetValue(rootEntityType, out entitySet))
            {
                return(false);
            }

            // free floating entity constructors are stored with a null EntitySet
            if (entitySet == null)
            {
                return(false);
            }

            // look for discriminator map
            return(m_discriminatorMaps.TryGetValue(entitySet, out discriminatorMap));
        }
Exemple #2
0
        /// <summary>
        /// Add the list of rel-properties for this type
        /// </summary>
        /// <param name="typeInfo">the type to process</param>
        private void AddRelProperties(TypeInfo typeInfo)
        {
            md.EntityTypeBase entityType = (md.EntityTypeBase)typeInfo.Type.EdmType;

            //
            // Walk through each rel-property defined for this specific type,
            // and add a corresponding property-ref
            //
            foreach (RelProperty p in m_relPropertyHelper.GetDeclaredOnlyRelProperties(entityType))
            {
                md.EdmType refType     = p.ToEnd.TypeUsage.EdmType;
                TypeInfo   refTypeInfo = GetTypeInfo(p.ToEnd.TypeUsage);

                //
                // We're dealing with a structured type again - flatten this out
                // as well
                //
                ExplodeType(refTypeInfo);

                foreach (PropertyRef nestedPropInfo in refTypeInfo.PropertyRefList)
                {
                    typeInfo.RootType.AddPropertyRef(nestedPropInfo.CreateNestedPropertyRef(p));
                }
            }

            //
            // Process all subtypes now
            //
            foreach (TypeInfo subTypeInfo in typeInfo.ImmediateSubTypes)
            {
                AddRelProperties(subTypeInfo);
            }
        }
 internal FacetDescription(string facetName,
                           EdmType facetType,
                           int? minValue,
                           int? maxValue,
                           object defaultValue,
                           bool isConstant,
                           string declaringTypeName)
 {
     _facetName = facetName;
     _facetType = facetType;
     _minValue = minValue;
     _maxValue = maxValue;
     
     // this ctor doesn't allow you to set the defaultValue to null
     if (defaultValue != null)
     {
         _defaultValue = defaultValue;
     }
     else
     {
         _defaultValue = _notInitializedSentinel;
     }
     _isConstant = isConstant;
     
     Validate(declaringTypeName);
     if (_isConstant)
     {
         UpdateMinMaxValueForConstant(_facetName, _facetType, ref _minValue, ref _maxValue, _defaultValue);
     }
 }
        /// <summary>
        /// The constructor for constructing a facet description object
        /// </summary>
        /// <param name="facetName">The name of this facet</param>
        /// <param name="facetType">The type of this facet</param>
        /// <param name="minValue">The min value for this facet</param>
        /// <param name="maxValue">The max value for this facet</param>
        /// <param name="defaultValue">The default value for this facet</param>
        /// <exception cref="System.ArgumentNullException">Thrown if either facetName, facetType or applicableType arguments are null</exception>
        internal FacetDescription(string facetName,
                                  EdmType facetType,
                                  int? minValue,
                                  int? maxValue,
                                  object defaultValue)
        {
            EntityUtil.CheckStringArgument(facetName, "facetName");
            EntityUtil.GenericCheckArgumentNull(facetType, "facetType");

            if (minValue.HasValue || maxValue.HasValue)
            {
                Debug.Assert(FacetDescription.IsNumericType(facetType), "Min and Max Values can only be specified for numeric facets");

                if (minValue.HasValue && maxValue.HasValue)
                {
                    Debug.Assert(minValue != maxValue, "minValue should not be equal to maxValue");
                }
            }

            _facetName = facetName;
            _facetType = facetType;
            _minValue = minValue;
            _maxValue = maxValue;
            _defaultValue = defaultValue;
        }
Exemple #5
0
        public static void VerifyEdmTypesEquivalent(LegacyMetadata.EdmType legacyEdmType, EdmType edmType)
        {
            Assert.Equal(legacyEdmType.FullName, edmType.FullName);

            Assert.True(
                (legacyEdmType.BaseType == null && edmType.BaseType == null) ||
                legacyEdmType.BaseType.FullName == edmType.BaseType.FullName);
            Assert.Equal(legacyEdmType.BuiltInTypeKind.ToString(), edmType.BuiltInTypeKind.ToString());
            Assert.Equal(
                ((LegacyMetadata.DataSpace) typeof(LegacyMetadata.EdmType)
                 .GetProperty("DataSpace", BindingFlags.Instance | BindingFlags.NonPublic)
                 .GetValue(legacyEdmType)).ToString(),
                ((DataSpace)typeof(EdmType)
                 .GetProperty("DataSpace", BindingFlags.Instance | BindingFlags.NonPublic)
                 .GetValue(edmType)).ToString());

            if (edmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveTypeKind)
            {
                var primitiveEdmType       = (PrimitiveType)edmType;
                var legacyPrimitiveEdmType = (LegacyMetadata.PrimitiveType)legacyEdmType;

                // EF5 geospatial types should be converted to EF6 spatial types
                var expectedClrEquivalentType =
                    legacyPrimitiveEdmType.ClrEquivalentType == typeof(LegacySpatial.DbGeography)
                        ? typeof(DbGeography)
                        : legacyPrimitiveEdmType.ClrEquivalentType == typeof(LegacySpatial.DbGeometry)
                              ? typeof(DbGeometry)
                              : legacyPrimitiveEdmType.ClrEquivalentType;

                Assert.Equal(expectedClrEquivalentType, primitiveEdmType.ClrEquivalentType);
                Assert.Equal(legacyPrimitiveEdmType.GetEdmPrimitiveType().FullName, primitiveEdmType.GetEdmPrimitiveType().FullName);
            }
        }
Exemple #6
0
        /// <summary>
        /// Creates generated view object for the combination of the <paramref name="extent"/> and the <paramref name="type"/>. 
        /// This constructor is used for regular cell-based view generation.
        /// </summary>
        internal static GeneratedView CreateGeneratedView(EntitySetBase extent,
                                                          EdmType type,
                                                          DbQueryCommandTree commandTree,
                                                          string eSQL,
                                                          StorageMappingItemCollection mappingItemCollection,
                                                          ConfigViewGenerator config)
        {
            // If config.GenerateEsql is specified, eSQL must be non-null.
            // If config.GenerateEsql is false, commandTree is non-null except the case when loading pre-compiled eSQL views.
            Debug.Assert(!config.GenerateEsql || !String.IsNullOrEmpty(eSQL), "eSQL must be specified");

            DiscriminatorMap discriminatorMap = null;
            if (commandTree != null)
            {
                commandTree = ViewSimplifier.SimplifyView(extent, commandTree);

                // See if the view matches the "discriminated" pattern (allows simplification of generated store commands)
                if (extent.BuiltInTypeKind == BuiltInTypeKind.EntitySet)
                {
                    if (DiscriminatorMap.TryCreateDiscriminatorMap((EntitySet)extent, commandTree.Query, out discriminatorMap))
                    {
                        Debug.Assert(discriminatorMap != null, "discriminatorMap == null after it has been created");
                    }
                }
            }

            return new GeneratedView(extent, type, commandTree, eSQL, discriminatorMap, mappingItemCollection, config);
        }
        internal QueryRewriter(EdmType generatedType, ViewgenContext context, ViewGenMode typesGenerationMode)
        {
            Debug.Assert(typesGenerationMode != ViewGenMode.GenerateAllViews);

            _typesGenerationMode = typesGenerationMode;
            _context = context;
            _generatedType = generatedType;
            _domainMap = context.MemberMaps.LeftDomainMap;
            _config = context.Config;
            _identifiers = context.CqlIdentifiers;
            _qp = new RewritingProcessor<Tile<FragmentQuery>>(new DefaultTileProcessor<FragmentQuery>(context.LeftFragmentQP));
            _extentPath = new MemberPath(context.Extent);
            _keyAttributes = new List<MemberPath>(MemberPath.GetKeyMembers(context.Extent, _domainMap));

            // populate _fragmentQueries and _views
            foreach (var leftCellWrapper in _context.AllWrappersForExtent)
            {
                var query = leftCellWrapper.FragmentQuery;
                Tile<FragmentQuery> tile = CreateTile(query);
                _fragmentQueries.Add(query);
                _views.Add(tile);
            }
            Debug.Assert(_views.Count > 0);

            AdjustMemberDomainsForUpdateViews();

            // must be done after adjusting domains
            _domainQuery = GetDomainQuery(FragmentQueries, generatedType);

            _usedViews = new HashSet<FragmentQuery>();
        }
Exemple #8
0
        /// <summary>
        /// Retrieves a mapping to CLR type for the given EDM type. Assumes the MetadataWorkspace has no    
        /// </summary>
        internal static ObjectTypeMapping GetObjectMapping(EdmType type, MetadataWorkspace workspace)
        {
            // Check if the workspace has cspace item collection registered with it. If not, then its a case
            // of public materializer trying to create objects from PODR or EntityDataReader with no context.
            ItemCollection collection;
            if (workspace.TryGetItemCollection(DataSpace.CSpace, out collection))
            {
                return (ObjectTypeMapping)workspace.GetMap(type, DataSpace.OCSpace);
            }
            else
            {
                EdmType ospaceType;
                EdmType cspaceType;
                // If its a case of EntityDataReader with no context, the typeUsage which is passed in must contain
                // a cspace type. We need to look up an OSpace type in the ospace item collection and then create
                // ocMapping
                if (type.DataSpace == DataSpace.CSpace)
                {
                    // if its a primitive type, then the names will be different for CSpace type and OSpace type
                    if (Helper.IsPrimitiveType(type))
                    {
                        ospaceType = workspace.GetMappedPrimitiveType(((PrimitiveType)type).PrimitiveTypeKind, DataSpace.OSpace);
                    }
                    else
                    {
                        // Metadata will throw if there is no item with this identity present.
                        // Is this exception fine or does object materializer code wants to wrap and throw a new exception
                        ospaceType = workspace.GetItem<EdmType>(type.FullName, DataSpace.OSpace);
                    }
                    cspaceType = type;
                }
                else
                {
                    // In case of PODR, there is no cspace at all. We must create a fake ocmapping, with ospace types
                    // on both the ends
                    ospaceType = type;
                    cspaceType = type;
                }

                // This condition must be hit only when someone is trying to materialize a legacy data reader and we
                // don't have the CSpace metadata.
                if (!Helper.IsPrimitiveType(ospaceType) && !Helper.IsEntityType(ospaceType) && !Helper.IsComplexType(ospaceType))
                {
                    throw EntityUtil.MaterializerUnsupportedType();
                }

                ObjectTypeMapping typeMapping;

                if (Helper.IsPrimitiveType(ospaceType))
                {
                    typeMapping = new ObjectTypeMapping(ospaceType, cspaceType);
                }
                else
                {
                    typeMapping = DefaultObjectMappingItemCollection.LoadObjectMapping(cspaceType, ospaceType, null);
                }

                return typeMapping;
            }
        }
Exemple #9
0
 /// <summary>
 /// Creates generated view object for the combination of the <paramref name="extent"/> and the <paramref name="type"/>. 
 /// This constructor is used for FK association sets only.
 /// </summary>
 internal static GeneratedView CreateGeneratedViewForFKAssociationSet(EntitySetBase extent,
                                                                      EdmType type,
                                                                      DbQueryCommandTree commandTree,
                                                                      StorageMappingItemCollection mappingItemCollection,
                                                                      ConfigViewGenerator config)
 {
     return new GeneratedView(extent, type, commandTree, null, null, mappingItemCollection, config);
 }
        internal void LogLoadMessage(string message, EdmType relatedType)
        {
            if (_logLoadMessage != null)
            {
                _logLoadMessage(message);
            }

            LogMessagesWithTypeInfo(message, relatedType);
        }
        /// <summary>
        /// A default mapping (property "Foo" maps by convention to column "Foo"), if allowed, has the lowest precedence.
        /// A mapping for a specific type (EntityType="Bar") takes precedence over a mapping for a hierarchy (EntityType="IsTypeOf(Bar)"))
        /// If there are two hierarchy mappings, the most specific mapping takes precedence. 
        /// For instance, given the types Base, Derived1 : Base, and Derived2 : Derived1, 
        /// w.r.t. Derived1 "IsTypeOf(Derived1)" takes precedence over "IsTypeOf(Base)" when you ask for the rename of Derived1
        /// </summary>
        /// <param name="lineInfo">Empty for default rename mapping.</param>
        internal string GetRename(EdmType type, out IXmlLineInfo lineInfo)
        {
            //Contract.Requires(type != null);

            Debug.Assert(type is StructuralType, "we can only rename structural type");

            var rename = _renameCache.Evaluate(type as StructuralType);
            lineInfo = rename.LineInfo;
            return rename.ColumnName;
        }
Exemple #12
0
        /// <summary>
        /// Is this type a UDT? (ie) a structural type supported by the store
        /// </summary>
        /// <param name="type">the type in question</param>
        /// <returns>true, if the type was a UDT</returns>
        internal static bool IsUdt(md.EdmType type)
        {
#if UDT_SUPPORT
            // Ideally this should be as simple as:
            // return TypeUsage.HasExtendedAttribute(type, MetadataConstants.UdtAttribute);
            // The definition below is 'Type is a ComplexType defined in the store'.
            return(BuiltInTypeKind.ComplexType == type.BuiltInTypeKind &&
                   TypeHelpers.HasExtendedAttribute(type, MetadataConstants.TargetAttribute));
#else
            return(false);
#endif
        }
Exemple #13
0
 private static LegacyMetadata.TypeUsage CreateLegacyTypeUsage
     (LegacyMetadata.EdmType edmType, IEnumerable <LegacyMetadata.Facet> facets)
 {
     return((LegacyMetadata.TypeUsage)LegacyTypeUsageCtor.Invoke(
                BindingFlags.CreateInstance,
                null,
                new object[]
     {
         edmType,
         facets
     },
                CultureInfo.InvariantCulture));
 }
 internal bool TryGetEdmType(string typeName, out EdmType edmType)
 {
     edmType = null;
     foreach (EdmType loadedEdmType in this.TypesInAssembly)
     {
         if (loadedEdmType.Identity == typeName)
         {
             edmType = loadedEdmType;
             break;
         }
     }
     return (edmType != null);
 }
        private void LogMessagesWithTypeInfo(string message, EdmType relatedType)
        {
            Debug.Assert(relatedType != null, "have to have a type with this message");

            if (_messages.ContainsKey(relatedType))
            {
                // if this type already contains loading message, append the new message to the end
                _messages[relatedType].AppendLine(message);
            }
            else
            {
                _messages.Add(relatedType, new StringBuilder(message));
            }
        }
        /// <summary>
        /// Check to see if the type is already loaded - either in the typesInLoading, or ObjectItemCollection or
        /// in the global cache
        /// </summary>
        /// <param name="clrType"></param>
        /// <param name="edmType"></param>
        /// <returns></returns>
        private bool TryGetLoadedType(Type clrType, out EdmType edmType)
        {
            if (SessionData.TypesInLoading.TryGetValue(clrType.FullName, out edmType) ||
                TryGetCachedEdmType(clrType, out edmType))
            {
                // Check to make sure the CLR type we got is the same as the given one
                if (edmType.ClrType != clrType)
                {
                    SessionData.EdmItemErrors.Add(new EdmItemError(System.Data.Entity.Strings.NewTypeConflictsWithExistingType(
                                                clrType.AssemblyQualifiedName, edmType.ClrType.AssemblyQualifiedName), edmType));
                    edmType = null;
                    return false;
                }
                return true;
            }


            // Let's check to see if this type is a ref type, a nullable type, or a collection type, these are the types that
            // we need to take special care of them
            if (clrType.IsGenericType)
            {
                Type genericType = clrType.GetGenericTypeDefinition();

                // Try to resolve the element type into a type object
                EdmType elementType;
                if (!TryGetLoadedType(clrType.GetGenericArguments()[0], out elementType))
                    return false;

                if (typeof(System.Collections.IEnumerable).IsAssignableFrom(clrType))
                {
                    EntityType entityType = elementType as EntityType;
                    if (entityType == null)
                    {
                        // return null and let the caller deal with the error handling
                        return false;
                    }
                    edmType = entityType.GetCollectionType();
                }
                else
                {
                    edmType = elementType;
                }

                return true;
            }


            edmType = null;
            return false;
        }
        /// <summary>
        /// Returns all the FacetDescriptions for a particular type
        /// </summary>
        /// <param name="type">the type to return FacetDescriptions for.</param>
        /// <returns>The FacetDescriptions for the type given.</returns>
        public override ReadOnlyCollection<FacetDescription> GetFacetDescriptions(EdmType type)
        {
            Debug.Assert(type is PrimitiveType, "EdmProviderManifest.GetFacetDescriptions(): Argument is not a PrimitiveType");

            InitializeFacetDescriptions();

            // Some types may not have facets, so just try to get them, if there aren't any, just return an empty list
            ReadOnlyCollection<FacetDescription> collection = null;
            if (_facetDescriptions.TryGetValue(type as PrimitiveType, out collection))
            {
                return collection;
            }
            return Helper.EmptyFacetDescriptionEnumerable;
        }
        /// <summary>
        /// Construct a new ObjectTypeMapping object
        /// </summary>
        /// <param name="clrType"></param>
        /// <param name="cdmType"></param>
        internal ObjectTypeMapping(EdmType clrType, EdmType cdmType) {
            Debug.Assert(clrType.BuiltInTypeKind == cdmType.BuiltInTypeKind, "BuiltInTypeKind must be the same for both types");
            this.m_clrType = clrType;
            this.m_cdmType = cdmType;
            identity = clrType.Identity + ObjectMslConstructs.IdentitySeperator + cdmType.Identity;

            if (Helper.IsStructuralType(cdmType))
            {
                m_memberMapping = new Dictionary<string, ObjectMemberMapping>(((StructuralType)cdmType).Members.Count);
            }
            else
            {
                m_memberMapping = EmptyMemberMapping;
            }
        }
        /// <summary>
        /// The constructor for MetadataProperty taking in all the ingredients for creating TypeUsage and the actual value
        /// </summary>
        /// <param name="name">The name of the attribute</param>
        /// <param name="edmType">The edm type of the attribute</param>
        /// <param name="isCollectionType">Whether the collection type of the given edm type should be used</param>
        /// <param name="value">The value of the attribute</param>
        internal MetadataProperty(string name, EdmType edmType, bool isCollectionType, object value)
        {
            EntityUtil.CheckArgumentNull(edmType, "edmType");

            _name = name;
            _value = value;
            if (isCollectionType)
            {
                _typeUsage = TypeUsage.Create(edmType.GetCollectionType());
            }
            else
            {
                _typeUsage = TypeUsage.Create(edmType);
            }
            _propertyKind = PropertyKind.System;
        }
        /// <summary>
        /// The constructor for MetadataProperty taking in all the ingredients for creating TypeUsage and the actual value
        /// </summary>
        /// <param name="name">The name of the attribute</param>
        /// <param name="edmType">The edm type of the attribute</param>
        /// <param name="isCollectionType">Whether the collection type of the given edm type should be used</param>
        /// <param name="value">The value of the attribute</param>
        internal MetadataProperty(string name, EdmType edmType, bool isCollectionType, object value)
        {
            //Contract.Requires(edmType != null);

            _name = name;
            _value = value;
            if (isCollectionType)
            {
                _typeUsage = TypeUsage.Create(edmType.GetCollectionType());
            }
            else
            {
                _typeUsage = TypeUsage.Create(edmType);
            }
            _propertyKind = PropertyKind.System;
        }
        private string GetTypeRelatedLogMessage(EdmType relatedType)
        {
            Debug.Assert(relatedType != null, "have to pass in a type to get the message");

            if (_messages.ContainsKey(relatedType))
            {
                return new StringBuilder()
                    .AppendLine()
                    .AppendLine(Strings.ExtraInfo)
                    .AppendLine(_messages[relatedType].ToString()).ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        internal StateManagerTypeMetadata(EdmType edmType, ObjectTypeMapping mapping)
        {
            Debug.Assert(null != edmType, "null EdmType");
            Debug.Assert(
                Helper.IsEntityType(edmType) ||
                Helper.IsComplexType(edmType),
                "not Complex or EntityType");
            Debug.Assert(
                ReferenceEquals(mapping, null) ||
                ReferenceEquals(mapping.EdmType, edmType),
                "different EdmType instance");

            _typeUsage = TypeUsage.Create(edmType);
            _recordInfo = new DataRecordInfo(_typeUsage);

            var members = TypeHelpers.GetProperties(edmType);
            _members = new StateManagerMemberMetadata[members.Count];
            _objectNameToOrdinal = new Dictionary<string, int>(members.Count);
            _cLayerNameToOrdinal = new Dictionary<string, int>(members.Count);

            ReadOnlyMetadataCollection<EdmMember> keyMembers = null;
            if (Helper.IsEntityType(edmType))
            {
                keyMembers = ((EntityType)edmType).KeyMembers;
            }

            for (var i = 0; i < _members.Length; ++i)
            {
                var member = members[i];

                ObjectPropertyMapping memberMap = null;
                if (null != mapping)
                {
                    memberMap = mapping.GetPropertyMap(member.Name);
                    if (null != memberMap)
                    {
                        _objectNameToOrdinal.Add(memberMap.ClrProperty.Name, i); // olayer name
                    }
                }
                _cLayerNameToOrdinal.Add(member.Name, i); // clayer name

                // Determine whether this member is part of the identity of the entity.
                _members[i] = new StateManagerMemberMetadata(memberMap, member, ((null != keyMembers) && keyMembers.Contains(member)));
            }
        }
 public static object MapType(object value, EdmType type)
 {
     switch (type.ToString())
     {
         case "Edm.Int32":
             int castedValue;
             int.TryParse(value.ToString(), out castedValue);
             return castedValue;
         case "Edm.DateTime":
             DateTime castedDate = Convert.ToDateTime(value.ToString());
             return castedDate;
         case "Edm.DateTimeLong":
             return value;
             break;
         case "Edm.Boolean":
             Boolean castedBoolean = Convert.ToBoolean(value);
             return castedBoolean;
         default://String
             return value;
     }
 }
 private void EmitKnownTypeAttributes(EdmType baseType, ClientApiGenerator generator, CodeTypeDeclaration typeDecl)
 {
     foreach (EdmType edmType in generator.GetDirectSubTypes(baseType))
     {
         Debug.Assert(edmType.BaseType == baseType, "The types must be directly derived from basetype");
         
         CodeTypeReference subTypeRef;
         if (generator.Language == LanguageOption.GenerateCSharpCode)
         {
             bool useGlobalPrefix = true;
             subTypeRef = generator.GetFullyQualifiedTypeReference(edmType, useGlobalPrefix);
         }
         else
         {
             Debug.Assert(generator.Language == LanguageOption.GenerateVBCode, "Did you add a new language?");
             subTypeRef = generator.GetLeastPossibleQualifiedTypeReference(edmType);
         }
         CodeAttributeDeclaration attribute = EmitSimpleAttribute("System.Runtime.Serialization.KnownTypeAttribute", new CodeTypeOfExpression(subTypeRef));
         typeDecl.CustomAttributes.Add(attribute);
     }
 }
        private bool TryGetCSpaceTypeMatch(Type type, out EdmType cspaceType)
        {
            // brute force try and find a matching name
            KeyValuePair<EdmType, int> pair;
            if (SessionData.ConventionCSpaceTypeNames.TryGetValue(type.Name, out pair))
            {
                if (pair.Value == 1)
                {
                    // we found a type match
                    cspaceType = pair.Key;
                    return true;
                }
                else
                {
                    Debug.Assert(pair.Value > 1, "how did we get a negative count of types in the dictionary?");
                    SessionData.EdmItemErrors.Add(new EdmItemError(Strings.Validator_OSpace_Convention_MultipleTypesWithSameName(type.Name), pair.Key));
                }
            }

            cspaceType = null;
            return false;
        }
        /// <summary>
        /// Build the collectionColumnMap from a store datareader, a type and an entitySet.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="edmType"></param>
        /// <param name="entitySet"></param>
        /// <returns></returns>
        internal static CollectionColumnMap CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary<string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList)
        {
            Debug.Assert(Helper.IsEntityType(edmType) || null == entitySet, "The specified non-null EntitySet is incompatible with the EDM type specified.");

            // Next, build the ColumnMap directly from the edmType and entitySet provided.
            ColumnMap[] propertyColumnMaps = GetColumnMapsForType(storeDataReader, edmType, renameList);
            ColumnMap elementColumnMap = null;

            // NOTE: We don't have a null sentinel here, because the stored proc won't 
            //       return one anyway; we'll just presume the data's always there.
            if (Helper.IsRowType(edmType))
            {
                elementColumnMap = new RecordColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null);
            }
            else if (Helper.IsComplexType(edmType))
            {
                elementColumnMap = new ComplexTypeColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null);
            }
            else if (Helper.IsScalarType(edmType))
            {
                if (storeDataReader.FieldCount != 1)
                {
                    throw EntityUtil.CommandExecutionDataReaderFieldCountForScalarType();
                }
                elementColumnMap = new ScalarColumnMap(TypeUsage.Create(edmType), edmType.Name, 0, 0);
            }
            else if (Helper.IsEntityType(edmType))
            {
                elementColumnMap = CreateEntityTypeElementColumnMap(storeDataReader, edmType, entitySet, propertyColumnMaps, null/*renameList*/);
            }
            else
            {
                Debug.Assert(false, "unexpected edmType?");
            }
            CollectionColumnMap collection = new SimpleCollectionColumnMap(edmType.GetCollectionType().TypeUsage, edmType.Name, elementColumnMap, null, null);
            return collection;
        }
        private static bool TryGetCommonType(EdmType edmType1, EdmType edmType2, out EdmType commonEdmType)
        {
            Debug.Assert(edmType1 != null && edmType2 != null);

            if (edmType2 == edmType1)
            {
                commonEdmType = edmType1;
                return true;
            }

            if (Helper.IsPrimitiveType(edmType1) && Helper.IsPrimitiveType(edmType2))
            {
                return TryGetCommonType((PrimitiveType)edmType1,
                                                 (PrimitiveType)edmType2,
                                                 out commonEdmType);
            }

            else if (Helper.IsCollectionType(edmType1) && Helper.IsCollectionType(edmType2))
            {
                return TryGetCommonType((CollectionType)edmType1,
                                                  (CollectionType)edmType2,
                                                  out commonEdmType);
            }

            else if (Helper.IsEntityTypeBase(edmType1) && Helper.IsEntityTypeBase(edmType2))
            {
                return TryGetCommonBaseType(edmType1,
                                            edmType2,
                                            out commonEdmType);
            }

            else if (Helper.IsRefType(edmType1) && Helper.IsRefType(edmType2))
            {
                return TryGetCommonType((RefType)edmType1,
                                           (RefType)edmType2,
                                           out commonEdmType);
            }

            else if (Helper.IsRowType(edmType1) && Helper.IsRowType(edmType2))
            {
                return TryGetCommonType((RowType)edmType1,
                                           (RowType)edmType2,
                                           out commonEdmType);
            }
            else
            {
                commonEdmType = null;
                return false;
            }
        }
Exemple #28
0
 internal static bool Equals(md.EdmType x, md.EdmType y)
 {
     return(x.Identity.Equals(y.Identity));
 }
        private static bool TryGetCommonType(RefType refType1, RefType reftype2, out EdmType commonType)
        {
            Debug.Assert(refType1.ElementType != null && reftype2.ElementType != null);

            if (!TryGetCommonType(refType1.ElementType, reftype2.ElementType, out commonType))
            {
                return false;
            }

            commonType = new RefType((EntityType)commonType);
            return true;
        }
        /// <summary>
        /// determines if <paramref name="type"/> is primitive or enumeration type
        /// </summary>
        /// <param name="type">Type to verify.</param>
        /// <returns><c>true</c> if <paramref name="type"/> is primitive or enumeration type. <c>false</c> otherwise.</returns>
        internal static bool IsScalarType(EdmType type)
        {
            Debug.Assert(type != null, "type != null");

            return Helper.IsPrimitiveType(type) || Helper.IsEnumType(type);
        }
 /// <summary>
 /// determines if two types are equivalent or if fromType is promotable to toType 
 /// </summary>
 /// <param name="fromType"></param>
 /// <param name="toType"></param>
 /// <returns>true if fromType equivalent or promotable to toType, false otherwise</returns>
 internal static bool IsStructurallyEqualOrPromotableTo(EdmType fromType, EdmType toType)
 {
     return IsStructurallyEqualOrPromotableTo(TypeUsage.Create(fromType), TypeUsage.Create(toType));
 }
        private static bool TryGetCommonType(PrimitiveType primitiveType1, PrimitiveType primitiveType2, out EdmType commonType)
        {
            commonType = null;

            if (IsSubTypeOf(primitiveType1, primitiveType2))
            {
                commonType = primitiveType2;
                return true;
            }

            if (IsSubTypeOf(primitiveType2, primitiveType1))
            {
                commonType = primitiveType1;
                return true;
            }

            objectModel.ReadOnlyCollection<PrimitiveType> superTypes = GetPrimitiveCommonSuperTypes(primitiveType1, primitiveType2);
            if (superTypes.Count > 0)
            {
                commonType = superTypes[0];
                return true;
            }

            return false;
        }
        private static bool TryGetCommonBaseType(EdmType type1, EdmType type2, out EdmType commonBaseType)
        {
            // put all the other base types in a dictionary
            Dictionary<EdmType, byte> otherBaseTypes = new Dictionary<EdmType, byte>();
            for (EdmType ancestor = type2; ancestor != null; ancestor = ancestor.BaseType)
            {
                otherBaseTypes.Add(ancestor, 0);
            }

            // walk up the ancestor chain, and see if any of them are 
            // common to the otherTypes ancestors
            for (EdmType ancestor = type1; ancestor != null; ancestor = ancestor.BaseType)
            {

                if (otherBaseTypes.ContainsKey(ancestor))
                {
                    commonBaseType = ancestor;
                    return true;
                }
            }

            commonBaseType = null;
            return false;
        }
        private static bool TryGetCommonType(CollectionType collectionType1, CollectionType collectionType2, out EdmType commonType)
        {
            TypeUsage commonTypeUsage = null;
            if (!TryGetCommonType(collectionType1.TypeUsage, collectionType2.TypeUsage, out commonTypeUsage))
            {
                commonType = null;
                return false;
            }

            commonType = new CollectionType(commonTypeUsage);
            return true;
        }
 /// <summary>
 /// Initialize a new attribute
 /// </summary>
 /// <param name="type">Sets Type property</param>
 /// <param name="isCollectionType">Sets IsCollectionType property</param>
 private MetadataPropertyAttribute(EdmType type, bool isCollectionType)
 {
     Debug.Assert(null != type);
     _type             = type;
     _isCollectionType = isCollectionType;
 }
        private static bool TryGetCommonType(RowType rowType1, RowType rowType2, out EdmType commonRowType)
        {
            if (rowType1.Properties.Count != rowType2.Properties.Count ||
                rowType1.InitializerMetadata != rowType2.InitializerMetadata)
            {
                commonRowType = null;
                return false;
            }

            // find a common type for every property
            List<EdmProperty> commonProperties = new List<EdmProperty>();
            for (int i = 0; i < rowType1.Properties.Count; i++)
            {
                TypeUsage columnCommonTypeUsage;
                if (!TryGetCommonType(rowType1.Properties[i].TypeUsage, rowType2.Properties[i].TypeUsage, out columnCommonTypeUsage))
                {
                    commonRowType = null;
                    return false;
                }

                commonProperties.Add(new EdmProperty(rowType1.Properties[i].Name, columnCommonTypeUsage));
            }

            commonRowType = new RowType(commonProperties, rowType1.InitializerMetadata);
            return true;
        }
        internal bool ContainsType(string typeName)
        {
            EdmType edmType = null;

            return(TryGetEdmType(typeName, out edmType));
        }
 /// <summary>
 /// Determines if the given edmType is equal comparable. Consult "EntitySql Language Specification", 
 /// section 7 - Comparison and Dependent Operations for details.
 /// </summary>
 /// <param name="edmType">an instance of an EdmType</param>
 /// <returns>true if edmType is equal-comparable, false otherwise</returns>
 private static bool IsEqualComparable(EdmType edmType)
 {
     if (Helper.IsPrimitiveType(edmType) || Helper.IsRefType(edmType) || Helper.IsEntityType(edmType) || Helper.IsEnumType(edmType))
     {
         return true;
     }
     else if (Helper.IsRowType(edmType))
     {
         RowType rowType = (RowType)edmType;
         foreach (EdmProperty rowProperty in rowType.Properties)
         {
             if (!IsEqualComparable(rowProperty.TypeUsage))
             {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
Exemple #39
0
        /// <summary>
        /// Returns all the FacetDescriptions for a particular type
        /// </summary>
        /// <param name="type">the type to return FacetDescriptions for.</param>
        /// <returns>The FacetDescriptions for the type given.</returns>
        public override System.Collections.ObjectModel.ReadOnlyCollection <FacetDescription> GetFacetDescriptions(EdmType type)
        {
            if (Helper.IsPrimitiveType(type) && ((PrimitiveType)type).DataSpace == DataSpace.OSpace)
            {
                // we don't have our own facets, just defer to the edm primitive type facets
                PrimitiveType basePrimitive = (PrimitiveType)type.BaseType;
                return(basePrimitive.ProviderManifest.GetFacetDescriptions(basePrimitive));
            }

            return(Helper.EmptyFacetDescriptionEnumerable);
        }