Exemplo n.º 1
0
        public override string GetStoreType(EdmProperty property)
        {
            if (property.TypeUsage.EdmType.Name == "int")
                return "INTEGER";

            return base.GetStoreType(property);
        }
 private static bool IsServerGenerated(EdmProperty property) {
     MetadataProperty generated;
     if (property.MetadataProperties.TryGetValue(StoreGeneratedMetadata, false, out generated)) {
         return "Identity" == (string)generated.Value || "Computed" == (string)generated.Value;
     }
     return false;
 }
        public string GetGenerationOption(EdmProperty property, EntityType entity)
        {
            string result = "";
            bool isPk = entity.KeyMembers.Contains(property);
            MetadataProperty storeGeneratedPatternProperty = null;
            string storeGeneratedPatternPropertyValue = "None";

            if (property.MetadataProperties.TryGetValue(MetadataConstants.EDM_ANNOTATION_09_02 + ":StoreGeneratedPattern", false, out storeGeneratedPatternProperty))
                storeGeneratedPatternPropertyValue = storeGeneratedPatternProperty.Value.ToString();

            PrimitiveType edmType = (PrimitiveType)property.TypeUsage.EdmType;
            if (edmType == null && property.TypeUsage.EdmType is EnumType)
            {
                EnumType enumType = property.TypeUsage.EdmType as EnumType;
                edmType = enumType.UnderlyingType;
            }
            if (storeGeneratedPatternPropertyValue == "Computed")
            {
                result = ".HasDatabaseGeneratedOption(new Nullable<DatabaseGeneratedOption>(DatabaseGeneratedOption.Computed))";
            }
            else if ((edmType.ClrEquivalentType == typeof(int)) || (edmType.ClrEquivalentType == typeof(short)) || (edmType.ClrEquivalentType == typeof(long)))
            {
                if (isPk && (storeGeneratedPatternPropertyValue != "Identity"))
                    result = ".HasDatabaseGeneratedOption(new Nullable<DatabaseGeneratedOption>(DatabaseGeneratedOption.None))";
                else if ((!isPk || (entity.KeyMembers.Count > 1)) && (storeGeneratedPatternPropertyValue == "Identity"))
                    result = ".HasDatabaseGeneratedOption(new Nullable<DatabaseGeneratedOption>(DatabaseGeneratedOption.Identity))";
            }
            return result;
        }
        internal FunctionImportMappingComposable(
            EdmFunction functionImport,
            EdmFunction targetFunction,
            List<Tuple<StructuralType, List<StorageConditionPropertyMapping>, List<StoragePropertyMapping>>> structuralTypeMappings,
            EdmProperty[] targetFunctionKeys,
            StorageMappingItemCollection mappingItemCollection,
            string sourceLocation,
            LineInfo lineInfo) 
            : base(functionImport, targetFunction)
        {
            EntityUtil.CheckArgumentNull(mappingItemCollection, "mappingItemCollection");
            Debug.Assert(functionImport.IsComposableAttribute, "functionImport.IsComposableAttribute");
            Debug.Assert(targetFunction.IsComposableAttribute, "targetFunction.IsComposableAttribute");
            Debug.Assert(functionImport.EntitySet == null || structuralTypeMappings != null, "Function import returning entities must have structuralTypeMappings.");
            Debug.Assert(structuralTypeMappings == null || structuralTypeMappings.Count > 0, "Non-null structuralTypeMappings must not be empty.");
            EdmType resultType;
            Debug.Assert(
                structuralTypeMappings != null ||
                MetadataHelper.TryGetFunctionImportReturnType<EdmType>(functionImport, 0, out resultType) && TypeSemantics.IsScalarType(resultType),
                "Either type mappings should be specified or the function import should be Collection(Scalar).");
            Debug.Assert(functionImport.EntitySet == null || targetFunctionKeys != null, "Keys must be inferred for a function import returning entities.");
            Debug.Assert(targetFunctionKeys == null || targetFunctionKeys.Length > 0, "Keys must be null or non-empty.");

            m_mappingItemCollection = mappingItemCollection;
            // We will use these parameters to target s-space function calls in the generated command tree. 
            // Since enums don't exist in s-space we need to use the underlying type.
            m_commandParameters = functionImport.Parameters.Select(p => TypeHelpers.GetPrimitiveTypeUsageForScalar(p.TypeUsage).Parameter(p.Name)).ToArray();
            m_structuralTypeMappings = structuralTypeMappings;
            m_targetFunctionKeys = targetFunctionKeys;
            m_sourceLocation = sourceLocation;
            m_lineInfo = lineInfo;
        }
Exemplo n.º 5
0
        public override string GetStoreType(EdmProperty property)
        {
            if (property.TypeUsage.EdmType.Name == "guid")
                return "CHAR(36) BINARY";

            return base.GetStoreType(property);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Get the Var corresponding to a specific property
 /// </summary>
 /// <param name="p">the requested property</param>
 /// <param name="v">the corresponding Var</param>
 /// <returns>true, if the Var was found</returns>
 internal bool TryGetVar(md.EdmProperty p, out Var v)
 {
     if (m_propertyToVarMap == null)
     {
         InitPropertyToVarMap();
     }
     return(m_propertyToVarMap.TryGetValue(p, out v));
 }
        internal StorageModificationFunctionResultBinding(string columnName, EdmProperty property)
        {
            //Contract.Requires(columnName != null);
            //Contract.Requires(property != null);

            ColumnName = columnName;
            Property = property;
        }
 /// <summary>
 /// Construct a new instance of the FieldDescriptor class that describes a property
 /// on items of the supplied type.
 /// </summary>
 /// <param name="itemType">Type of object whose property is described by this FieldDescriptor.</param>
 /// <param name="isReadOnly">
 /// <b>True</b> if property value on item can be modified; otherwise <b>false</b>.
 /// </param>
 /// <param name="property">
 /// EdmProperty that describes the property on the item.
 /// </param>
 internal FieldDescriptor(Type itemType, bool isReadOnly, EdmProperty property)
     : base(property.Name, null)
 {
     _itemType = itemType;
     _property = property;
     _isReadOnly = isReadOnly;
     _fieldType = DetermineClrType(_property.TypeUsage);
     System.Diagnostics.Debug.Assert(_fieldType != null, "FieldDescriptor's CLR type has unexpected value of null.");
 }
 /// <summary>
 /// Construct a new Scalar EdmProperty mapping object
 /// </summary>
 /// <param name="member"></param>
 /// <param name="columnMember"></param>
 internal StorageScalarPropertyMapping(EdmProperty member, EdmProperty columnMember)
     : base(member) {
     Debug.Assert(columnMember != null);
     Debug.Assert(
         Helper.IsScalarType(member.TypeUsage.EdmType), 
         "StorageScalarPropertyMapping must only map primitive or enum types");
     Debug.Assert(Helper.IsPrimitiveType(columnMember.TypeUsage.EdmType), "StorageScalarPropertyMapping must only map primitive types");
     this.m_columnMember = columnMember;
 }
        private bool DetermineIsForeignKeyComponent(EdmProperty property) {
            var navigationProperties = property.DeclaringType.Members.OfType<NavigationProperty>();

            // Look at all NavigationProperties (i.e. strongly-type relationship columns) of the table this column belong to and
            // see if there is a foreign key that matches this property
            // If this is a 1 to 0..1 relationship and we are processing the more primary side. i.e in the Student in Student-StudentDetail
            // and this is the primary key we don't want to check the relationship type since if there are no constraints we will treat the primary key as a foreign key.
            return navigationProperties.Any(n => EFCodeFirstAssociationProvider.GetDependentPropertyNames(n, !IsPrimaryKey /* checkRelationshipType */).Contains(property.Name));
        }
Exemplo n.º 11
0
 public override string WriteCreateColumn(EdmProperty property, Version targetVersion)
 {
     var notnull = (property.Nullable ? "" : "NOT NULL");
     var identity = GetIdentity(property, targetVersion);
     return string.Format("{0} {1} {2} {3}",
                          FormatName(property.Name),
                          GetStoreType(property),
                          identity, notnull).Trim();
 }
 /// <summary>
 /// Construct a new condition Property mapping object
 /// </summary>
 /// <param name="cdmMember"></param>
 /// <param name="columnMember"></param>
 /// <param name="value"></param>
 /// <param name="isNull"></param>
 internal StorageConditionPropertyMapping(EdmProperty cdmMember, EdmProperty columnMember
     , object value, Nullable<bool> isNull) : base(cdmMember) {
     Debug.Assert((cdmMember != null) || (columnMember != null), "Both CDM and Column Members can not be specified for Condition Mapping");
     Debug.Assert((cdmMember == null) || (columnMember == null), "Either CDM or Column Members has to be specified for Condition Mapping");
     Debug.Assert((isNull.HasValue) || (value != null), "Both Value and IsNull can not be specified on Condition Mapping");
     Debug.Assert(!(isNull.HasValue) || (value == null), "Either Value or IsNull has to be specified on Condition Mapping");
     this.m_columnMember = columnMember;
     this.m_value = value;
     this.m_isNull = isNull;
 }
 /// <summary>
 /// Adds a <paramref name="property"/> to <paramref name="metadata"/>
 /// under type <paramref name="structuredType"/>
 /// </summary>
 /// <param name="metadata">Metadata document to be added to</param>
 /// <param name="property">Property to add</param>
 /// <param name="structuredType">Structured type to add property to</param>
 private static void AddProperty(ConstructableMetadata metadata, EdmProperty property, IEdmStructuredType structuredType)
 {
     if (property.BuiltInTypeKind == BuiltInTypeKind.EdmProperty)
     {
         AddPrimitiveProperty(metadata, DataTypeToSystemType((PrimitiveType)property.TypeUsage.EdmType, IsNullable(property.TypeUsage)), property, structuredType);
     }
     else if (property.BuiltInTypeKind == BuiltInTypeKind.ComplexType)
     {
         metadata.AddComplexProperty(structuredType, property.Name, metadata.FindType(property.TypeUsage.EdmType.FullName) as IEdmComplexType);
     }
 }
 internal StateManagerMemberMetadata(ObjectPropertyMapping memberMap, EdmProperty memberMetadata, bool isPartOfKey)
 {
     // if memberMap is null, then this is a shadowstate
     Debug.Assert(null != memberMap, "shadowstate not supported");
     Debug.Assert(null != memberMetadata, "CSpace should never be null");
     _clrProperty = memberMap.ClrProperty;
     _edmProperty = memberMetadata;
     _isPartOfKey = isPartOfKey;
     _isComplexType = (Helper.IsEntityType(_edmProperty.TypeUsage.EdmType) ||
                       Helper.IsComplexType(_edmProperty.TypeUsage.EdmType));
 }
Exemplo n.º 15
0
 public override string GetStoreType(EdmProperty property)
 {
     switch (property.TypeUsage.EdmType.Name)
     {
         case "datetime":
             return "DATE";
         case "nvarchar":
             return property.ToStoreType().Replace("nvarchar", "VARCHAR");
         default:
             return base.GetStoreType(property);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the list of key properties for an entity
        /// </summary>
        /// <param name="entityType"></param>
        /// <returns></returns>
        private static PropertyRefList GetKeyProperties(md.EntityType entityType)
        {
            PropertyRefList desiredProperties = new PropertyRefList();

            foreach (md.EdmMember p in entityType.KeyMembers)
            {
                md.EdmProperty edmP = p as md.EdmProperty;
                PlanCompiler.Assert(edmP != null, "EntityType had non-EdmProperty key member?");
                SimplePropertyRef pRef = new SimplePropertyRef(edmP);
                desiredProperties.Add(pRef);
            }
            return(desiredProperties);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Add a mapping from the propertyRef (of the old type) to the
 /// corresponding property in the new type.
 ///
 /// NOTE: Only to be used by StructuredTypeInfo
 /// </summary>
 /// <param name="propertyRef"></param>
 /// <param name="newProperty"></param>
 internal void AddPropertyMapping(PropertyRef propertyRef, md.EdmProperty newProperty)
 {
     m_propertyMap[propertyRef] = newProperty;
     if (propertyRef is TypeIdPropertyRef)
     {
         m_typeIdProperty = newProperty;
     }
     else if (propertyRef is EntitySetIdPropertyRef)
     {
         m_entitySetIdProperty = newProperty;
     }
     else if (propertyRef is NullSentinelPropertyRef)
     {
         m_nullSentinelProperty = newProperty;
     }
 }
Exemplo n.º 18
0
 /// <summary>
 /// Add a mapping from the propertyRef (of the old type) to the 
 /// corresponding property in the new type.
 /// 
 /// NOTE: Only to be used by StructuredTypeInfo
 /// </summary>
 /// <param name="propertyRef"></param>
 /// <param name="newProperty"></param>
 internal void AddPropertyMapping(PropertyRef propertyRef, EdmProperty newProperty)
 {
     m_propertyMap[propertyRef] = newProperty;
     if (propertyRef is TypeIdPropertyRef)
     {
         m_typeIdProperty = newProperty;
     }
     else if (propertyRef is EntitySetIdPropertyRef)
     {
         m_entitySetIdProperty = newProperty;
     }
     else if (propertyRef is NullSentinelPropertyRef)
     {
         m_nullSentinelProperty = newProperty;
     }
 }
Exemplo n.º 19
0
 static string GenerateColumn(EdmProperty property)
 {
     var column = new StringBuilder();
     column.Append(SqlGenerator.QuoteIdentifier(property.Name));
     column.Append(" ");
     column.Append(SqlGenerator.GetSqlPrimitiveType(property.TypeUsage));
     if (MetadataHelpers.IsStoreGeneratedIdentity(property))
     {
         column.Append(" GENERATED BY DEFAULT AS IDENTITY");
     }
     if (!property.Nullable)
     {
         column.Append(" NOT NULL");
     }
     return column.ToString();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Given a property on the principal end of a referential constraint, returns the corresponding property on the dependent end.
        /// Requires: The association has a referential constraint, and the specified principalProperty is one of the properties on the principal end.
        /// </summary>
        public EdmProperty GetCorrespondingDependentProperty(NavigationProperty navProperty, EdmProperty principalProperty)
        {
            if (navProperty == null)
            {
                throw new ArgumentNullException("navProperty");
            }

            if (principalProperty == null)
            {
                throw new ArgumentNullException("principalProperty");
            }

            ReadOnlyMetadataCollection<EdmProperty> fromProperties = GetPrincipalProperties(navProperty);
            ReadOnlyMetadataCollection<EdmProperty> toProperties = GetDependentProperties(navProperty);
            return toProperties[fromProperties.IndexOf(principalProperty)];
        }
        internal EntityDataSourceMemberPath(MetadataWorkspace ocWorkspace, EntityDataSourceMemberPath parent, EdmProperty property, bool isLocallyInteresting)
        {
            EntityDataSourceUtil.CheckArgumentNull(ocWorkspace, "ocWorkspace");
            EntityDataSourceUtil.CheckArgumentNull(property, "property");
            
            this.property = property;
            this.parent = parent;
            this.isLocallyInteresting = isLocallyInteresting;
            this.clrType = EntityDataSourceUtil.GetMemberClrType(ocWorkspace, property);
            this.isKey = IsPropertyAKey(property);

            // retrieve PropertyInfo (with respect to parent CLR type)
            StructuralType parentType = property.DeclaringType;
            Type parentClrType = EntityDataSourceUtil.GetClrType(ocWorkspace, parentType);

            this.propertyInfo = EntityDataSourceUtil.GetPropertyInfo(parentClrType, this.property.Name);
        }
Exemplo n.º 22
0
        private static Helpers.PropertyUsageAttributes SetPropertyUsageAttributes(Edm.EdmProperty p)
        {
            Helpers.PropertyUsageAttributes propertyUsageAttributes = new Helpers.PropertyUsageAttributes();
            propertyUsageAttributes.Name = p.Name;

            if (p.TypeUsage.EdmType.BuiltInTypeKind == Edm.BuiltInTypeKind.ComplexType)
            {
                propertyUsageAttributes.IsComplexType = true;
                foreach (Edm.EdmProperty property in ((Edm.ComplexType)p.TypeUsage.EdmType).Properties)
                {
                    Helpers.PropertyUsageAttributes subPropertyUsageAttributes = SetPropertyUsageAttributes(property);
                    propertyUsageAttributes.SubPropertyUsageAttributes.Add(subPropertyUsageAttributes);
                }
            }
            else
            {
                propertyUsageAttributes.IsComplexType = false;
                propertyUsageAttributes.MaxLength     = p.TypeUsage.EdmType.Name.ToLower() == "string" ? System.Convert.ToInt32(p.TypeUsage.Facets["MaxLength"].Value) : (-1);
                propertyUsageAttributes.Required      = !System.Convert.ToBoolean(p.TypeUsage.Facets["Nullable"].Value);
                propertyUsageAttributes.Type          = p.TypeUsage.EdmType.Name;
            }
            return(propertyUsageAttributes);
        }
Exemplo n.º 23
0
    private string GetFacetString(EdmProperty column)
    {
      StringBuilder sql = new StringBuilder();
      Facet facet;
      Facet fcDateTimePrecision = null;

      ReadOnlyMetadataCollection<Facet> facets = column.TypeUsage.Facets;

      if (column.TypeUsage.EdmType.BaseType.Name == "String")
      {
        // types tinytext, mediumtext, text & longtext don't have a length.
        if (!column.TypeUsage.EdmType.Name.EndsWith("text", StringComparison.OrdinalIgnoreCase))
        {
          if (facets.TryGetValue("MaxLength", true, out facet))
            sql.AppendFormat(" ({0})", facet.Value);
        }
      }
      else if (column.TypeUsage.EdmType.BaseType.Name == "Decimal")
      {
        Facet fcScale;
        Facet fcPrecision;
        if (facets.TryGetValue("Scale", true, out fcScale) && facets.TryGetValue("Precision", true, out fcPrecision))
        {
          // Enforce scale to a reasonable value.
          int scale = fcScale.Value == null ? 0 : ( int )( byte )fcScale.Value;
          if (scale == 0)
            scale = MySqlProviderManifest.DEFAULT_DECIMAL_SCALE;
          sql.AppendFormat("( {0}, {1} ) ", fcPrecision.Value, scale);
        }
      }
      else if (column.TypeUsage.EdmType.BaseType.Name == "DateTime")
      {
        if (serverVersion >= new Version(5, 6) && facets.TryGetValue("Precision", true, out fcDateTimePrecision))
        {        
           if (Convert.ToByte(fcDateTimePrecision.Value) >= 1)
              sql.AppendFormat("( {0} ) ", fcDateTimePrecision.Value);            
        }
      }
      

      if (facets.TryGetValue("Nullable", true, out facet) && (bool)facet.Value == false)
        sql.Append(" NOT NULL");

      if (facets.TryGetValue("StoreGeneratedPattern", true, out facet))
      {
        if (facet.Value.Equals(StoreGeneratedPattern.Identity))
        {

          if (column.TypeUsage.EdmType.BaseType.Name.StartsWith("Int"))
            sql.Append(" AUTO_INCREMENT UNIQUE");
          else if (column.TypeUsage.EdmType.BaseType.Name == "Guid")
            _guidIdentityColumns.Add(column.Name);
          else if (serverVersion >= new Version(5, 6) && column.TypeUsage.EdmType.BaseType.Name == "DateTime")
            sql.AppendFormat(" DEFAULT CURRENT_TIMESTAMP{0}", fcDateTimePrecision != null && Convert.ToByte(fcDateTimePrecision.Value) >= 1 ? "( " + fcDateTimePrecision.Value.ToString() + " )" : "");                              
          else
            throw new MySqlException("Invalid identity column type.");
        }      
      }
      return sql.ToString();
    }
Exemplo n.º 24
0
        /// <summary>
        /// Try get the new property for the supplied propertyRef
        /// </summary>
        /// <param name="propertyRef">property reference (on the old type)</param>
        /// <param name="throwIfMissing">throw if the property is not found</param>
        /// <param name="property">the corresponding property on the new type</param>
        /// <returns></returns>
        internal new bool TryGetNewProperty(PropertyRef propertyRef, bool throwIfMissing, out md.EdmProperty property)
        {
            bool result = m_propertyMap.TryGetValue(propertyRef, out property);

            if (throwIfMissing && !result)
            {
                {
                    PlanCompiler.Assert(false, "Unable to find property " + propertyRef.ToString() + " in type " + this.Type.EdmType.Identity);
                }
            }
            return(result);
        }
 /// <summary>
 /// Constrcut a new member mapping metadata object
 /// </summary>
 /// <param name="edmProperty"></param>
 /// <param name="clrProperty"></param>
 /// <param name="complexTypeMapping"></param>
 internal ObjectComplexPropertyMapping(EdmProperty edmProperty, EdmProperty clrProperty, ObjectTypeMapping complexTypeMapping)
     : base(edmProperty, clrProperty)
 {
     m_objectTypeMapping = complexTypeMapping;
 }
 /// <summary>
 /// Constrcut a new member mapping metadata object
 /// </summary>
 /// <param name="edmProperty"></param>
 /// <param name="clrProperty"></param>
 internal ObjectPropertyMapping(EdmProperty edmProperty, EdmProperty clrProperty)
     :
         base(edmProperty, clrProperty)
 {
 }
 /// <summary>
 /// Adds a Primitive Property to <paramref name="metadata"/>
 /// </summary>
 /// <param name="metadata">Metadata document to be added to</param>
 /// <param name="type">The type of the primitive property</param>
 /// <param name="property">Property to add</param>
 /// <param name="structuredType">Structured type to add property to</param>
 private static void AddPrimitiveProperty(ConstructableMetadata metadata, Type type, EdmProperty property, IEdmStructuredType structuredType)
 {
     if (property.DeclaringType is EntityType && ((EntityType)property.DeclaringType).KeyMembers.Contains(property.Name))
     {
         metadata.AddKeyProperty(structuredType, property.Name, type);
     }
     else if (type == typeof(Stream))
     {
         metadata.AddNamedStreamProperty(structuredType, property.Name);
     }
     else
     {
         metadata.AddPrimitiveProperty(structuredType, property.Name, type);
     }
 }
Exemplo n.º 28
0
 /// <summary>
 /// Try get the new property for the supplied propertyRef
 /// </summary>
 /// <param name="propertyRef">property reference (on the old type)</param>
 /// <param name="throwIfMissing">throw if the property is not found</param>
 /// <param name="newProperty">the corresponding property on the new type</param>
 /// <returns></returns>
 internal bool TryGetNewProperty(PropertyRef propertyRef, bool throwIfMissing, out md.EdmProperty newProperty)
 {
     return(this.RootType.TryGetNewProperty(propertyRef, throwIfMissing, out newProperty));
 }
 /// <summary>
 /// Determines whether <paramref name="property"/> is part of an etag based on annotations
 /// </summary>
 /// <param name="property">Property to check for etag</param>
 /// <returns>true if part of an etag otherwise false</returns>
 private static bool IsETagProperty(EdmProperty property)
 {
     return false;
     // return property.Annotations.OfType<ConcurrencyTokenAnnotation>().Any();
 }
 /// <summary>
 /// Adds a <paramref name="property"/> to <paramref name="metadata"/>
 /// under type <paramref name="structuredType"/>
 /// </summary>
 /// <param name="metadata">Metadata document to be added to</param>
 /// <param name="property">Property to add</param>
 /// <param name="structuredType">Structured type to add property to</param>
 private static void AddProperty(ConstructableMetadata metadata, EdmProperty property, IEdmStructuredType structuredType)
 {
     if (property.BuiltInTypeKind == BuiltInTypeKind.EdmProperty)
     {
         AddPrimitiveProperty(metadata, DataTypeToSystemType((PrimitiveType)property.TypeUsage.EdmType, IsNullable(property.TypeUsage)), property, structuredType);
     }
     else if (property.BuiltInTypeKind == BuiltInTypeKind.ComplexType)
     {
         metadata.AddComplexProperty(structuredType, property.Name, metadata.FindType(property.TypeUsage.EdmType.FullName) as IEdmComplexType);
     }
 }
Exemplo n.º 31
0
 /// <summary>
 /// True if the EdmProperty TypeUsage is Nullable, False otherwise.
 /// </summary>
 public bool IsNullable(EdmProperty property)
 {
     return property != null && IsNullable(property.TypeUsage);
 }
Exemplo n.º 32
0
        /// <summary>
        /// True if the EdmProperty is a key of its DeclaringType, False otherwise.
        /// </summary>
        public bool IsKey(EdmProperty property)
        {
            if (property != null && property.DeclaringType.BuiltInTypeKind == BuiltInTypeKind.EntityType)
            {
                return ((EntityType)property.DeclaringType).KeyMembers.Contains(property);
            }

            return false;
        }
Exemplo n.º 33
0
        /// <summary>
        /// Create a column map for an entitytype column.
        /// Currently, the key columns are not duplicated (ie) they point into the
        /// same locations as in the properties list.
        /// Note: we also don't handle keys that are properties of nested fields
        /// </summary>
        /// <param name="typeInfo">Type information for the type</param>
        /// <param name="name">column name</param>
        /// <param name="superTypeColumnMap">supertype information if any</param>
        /// <param name="discriminatorMap">Dictionary of typeid->column map information</param>
        /// <param name="allMaps">List of all column maps (including those without typeid)</param>
        /// <param name="handleRelProperties">should we handle rel-properties?</param>
        /// <returns></returns>
        private EntityColumnMap CreateEntityColumnMap(TypeInfo typeInfo, string name, EntityColumnMap superTypeColumnMap,
                                                      Dictionary <object, TypedColumnMap> discriminatorMap, List <TypedColumnMap> allMaps, bool handleRelProperties)
        {
            EntityColumnMap  columnMap             = null;
            List <ColumnMap> propertyColumnMapList = new List <ColumnMap>();

            // Copy over information from my supertype if it already exists
            if (superTypeColumnMap != null)
            {
                // get supertype properties
                foreach (ColumnMap c in superTypeColumnMap.Properties)
                {
                    propertyColumnMapList.Add(c);
                }
                // Now add on all of my "specific" properties
                foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type))
                {
                    ColumnMap propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name);
                    propertyColumnMapList.Add(propertyColumnMap);
                }
                // create the entity column map w/ information from my supertype
                columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), superTypeColumnMap.EntityIdentity);
            }
            else
            {
                SimpleColumnMap entitySetIdColumnMap = null;
                if (typeInfo.HasEntitySetIdProperty)
                {
                    entitySetIdColumnMap = CreateEntitySetIdColumnMap(typeInfo.EntitySetIdProperty);
                }

                // build up a list of key columns
                List <SimpleColumnMap> keyColumnMapList = new List <SimpleColumnMap>();
                // Create a dictionary to look up the key properties
                Dictionary <md.EdmProperty, ColumnMap> keyPropertyMap = new Dictionary <md.EdmProperty, ColumnMap>();

                foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type))
                {
                    ColumnMap propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name);
                    propertyColumnMapList.Add(propertyColumnMap);
                    // add property to keymap, if this property is part of the key
                    if (md.TypeSemantics.IsPartOfKey(property))
                    {
                        md.EdmProperty edmProperty = property as md.EdmProperty;
                        PlanCompiler.Assert(edmProperty != null, "EntityType key member is not property?");
                        keyPropertyMap[edmProperty] = propertyColumnMap;
                    }
                }

                // Build up the key list if required
                foreach (md.EdmMember keyProperty in TypeHelpers.GetEdmType <md.EntityType>(typeInfo.Type).KeyMembers)
                {
                    md.EdmProperty edmKeyProperty = keyProperty as md.EdmProperty;
                    PlanCompiler.Assert(edmKeyProperty != null, "EntityType key member is not property?");
                    SimpleColumnMap keyColumnMap = keyPropertyMap[edmKeyProperty] as SimpleColumnMap;
                    PlanCompiler.Assert(keyColumnMap != null, "keyColumnMap is null");
                    keyColumnMapList.Add(keyColumnMap);
                }

                //
                // Create the entity identity.
                //
                EntityIdentity identity = CreateEntityIdentity((md.EntityType)typeInfo.Type.EdmType, entitySetIdColumnMap, keyColumnMapList.ToArray());

                // finally create the entity column map
                columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), identity);
            }

            // if a dictionary is supplied, add myself to the dictionary (abstract types need not be added)
            if (discriminatorMap != null)
            {
                // where DiscriminatedNewInstanceOp is used, there will not be an explicit type id for an abstract type
                // or types that do not appear in the QueryView
                // (the mapping will not include such information)
                if (null != typeInfo.TypeId)
                {
                    discriminatorMap[typeInfo.TypeId] = columnMap;
                }
            }
            if (allMaps != null)
            {
                allMaps.Add(columnMap);
            }
            // Finally walk through my subtypes
            foreach (TypeInfo subTypeInfo in typeInfo.ImmediateSubTypes)
            {
                CreateEntityColumnMap(subTypeInfo, name, columnMap, discriminatorMap, allMaps, false);
            }

            //
            // Build up the list of rel property column maps
            //
            if (handleRelProperties)
            {
                BuildRelPropertyColumnMaps(typeInfo, true);
            }
            return(columnMap);
        }
Exemplo n.º 34
0
        internal EntityDataSourceReferenceKeyColumn(MetadataWorkspace workspace, EntityDataSourceReferenceGroup group, EdmProperty keyMember, EntityDataSourceColumn dependent)
            : base(CreateDisplayName(group, keyMember), dependent)
        {
            EntityDataSourceUtil.CheckArgumentNull(group, "group");
            EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember");
            Debug.Assert(EntityDataSourceUtil.IsScalar(keyMember.TypeUsage.EdmType), "Expected primitive or enum type for key members.");

            this.group = group;
            this.keyMember = keyMember;
            this.clrType = EntityDataSourceUtil.GetMemberClrType(workspace, keyMember);

            // if the association end is optional (0..1), make sure the CLR type
            // is also nullable
            if (this.group.End.CorrespondingAssociationEndMember.RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne)
            {
                this.clrType = EntityDataSourceUtil.MakeNullable(clrType);
                this.isNullable = true;
            }
        }
Exemplo n.º 35
0
        private static string CreateDisplayName(EntityDataSourceReferenceGroup group, EdmProperty keyMember)
        {
            EntityDataSourceUtil.CheckArgumentNull(group, "group");
            EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember");

            NavigationProperty navigationProperty;

            string result;

            if (EntityDataSourceUtil.TryGetCorrespondingNavigationProperty(group.End.CorrespondingAssociationEndMember, out navigationProperty))
            {
                result = navigationProperty.Name + "." + keyMember.Name;
            }
            else
            {
                // if there is no Navigation property, use the TargetTole and KeyMember name
                // TargetRole.KeyMember
                result = group.End.Name + "." + keyMember.Name;
            }

            return result;
        }
 /// <summary>
 /// Adds a Primitive Property to <paramref name="metadata"/>
 /// </summary>
 /// <param name="metadata">Metadata document to be added to</param>
 /// <param name="type">The type of the primitive property</param>
 /// <param name="property">Property to add</param>
 /// <param name="structuredType">Structured type to add property to</param>
 private static void AddPrimitiveProperty(ConstructableMetadata metadata, Type type, EdmProperty property, IEdmStructuredType structuredType)
 {
     if (property.DeclaringType is EntityType && ((EntityType)property.DeclaringType).KeyMembers.Contains(property.Name))
     {
         metadata.AddKeyProperty(structuredType, property.Name, type, IsETagProperty(property));
     }
     else if (type == typeof(Stream))
     {
         metadata.AddNamedStreamProperty(structuredType, property.Name);
     }
     else
     {
         metadata.AddPrimitiveProperty(structuredType, property.Name, type, IsETagProperty(property));
     }
 }
 private bool IsPropertyAKey(EdmProperty property)
 {
     bool isKey = false;
     EntityType entityType = property.DeclaringType as EntityType;
     if (null != entityType)
     {
         isKey = entityType.KeyMembers.Contains(property);
     }
     return isKey;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Add properties for all the build in complex type
 /// </summary>
 /// <param name="builtInTypeKind">The type of the built In type whose properties are being added</param>
 /// <param name="properties">properties of the built in type</param>
 private static void AddBuiltInTypeProperties(BuiltInTypeKind builtInTypeKind, EdmProperty[] properties)
 {
     ComplexType complexType = (ComplexType)GetBuiltInType(builtInTypeKind);
     if (properties != null)
     {
         for (int i = 0; i < properties.Length; i++)
         {
             complexType.AddMember(properties[i]);
         }
     }
 }
 /// <summary>
 /// Construct a new End Property mapping object
 /// </summary>
 /// <param name="member"></param>
 internal StorageEndPropertyMapping(EdmProperty member)
     : base(member) {
 }
Exemplo n.º 40
0
 /// <summary>
 /// Create a column map for the typeid column
 /// </summary>
 /// <param name="prop"></param>
 /// <returns></returns>
 private SimpleColumnMap CreateTypeIdColumnMap(md.EdmProperty prop)
 {
     return(CreateSimpleColumnMap(md.Helper.GetModelTypeUsage(prop), c_TypeIdColumnName));
 }