Example #1
0
        private void MapComplexType(IComplexTypeConfiguration complexType)
        {
            PropertyInfo[] properties = ConventionsHelpers.GetProperties(complexType);
            foreach (PropertyInfo property in properties)
            {
                bool isCollection;
                IStructuralTypeConfiguration mappedType;

                PropertyKind propertyKind = GetPropertyType(property, out isCollection, out mappedType);

                if (propertyKind == PropertyKind.Primitive || propertyKind == PropertyKind.Complex)
                {
                    MapStructuralProperty(complexType, property, propertyKind, isCollection);
                }
                else
                {
                    // navigation property in a complex type ?
                    if (!isCollection)
                    {
                        if (mappedType == null)
                        {
                            // the user told nothing about this type and this is the first time we are seeing this type.
                            // complex types cannot contain entities. So, treat it as complex property.
                            complexType.AddComplexProperty(property);
                        }
                        else
                        {
                            if (_explicitlyAddedTypes.Contains(mappedType))
                            {
                                // user told us that this an entity type.
                                throw Error.InvalidOperation(SRResources.ComplexTypeRefersToEntityType, complexType.ClrType.FullName, mappedType.ClrType.FullName, property.Name);
                            }
                            else
                            {
                                // we tried to be over-smart earlier and made the bad choice. so patch up now.
                                ReconfigureEntityTypesAsComplexType(new IEntityTypeConfiguration[] { mappedType as IEntityTypeConfiguration });
                                complexType.AddComplexProperty(property);
                            }
                        }
                    }
                    else
                    {
                        throw Error.NotSupported(SRResources.CollectionPropertiesNotSupported, property.Name, property.ReflectedType.FullName);
                    }
                }
            }
        }
 private void MapComplexType(IComplexTypeConfiguration complexType)
 {
     PropertyInfo[] properties = ConventionsHelpers.GetProperties(complexType.ClrType);
     foreach (PropertyInfo property in properties)
     {
         if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(property.PropertyType) != null)
         {
             PrimitivePropertyConfiguration primitiveProperty = complexType.AddProperty(property);
             primitiveProperty.OptionalProperty = IsNullable(property.PropertyType);
         }
         else
         {
             complexType.AddComplexProperty(property);
         }
     }
 }
        private void MapComplexType(IComplexTypeConfiguration complexType)
        {
            PropertyInfo[] properties = ConventionsHelpers.GetProperties(complexType);
            foreach (PropertyInfo property in properties)
            {
                bool isCollection;
                IStructuralTypeConfiguration mappedType;

                PropertyKind propertyKind = GetPropertyType(property, out isCollection, out mappedType);

                if (propertyKind == PropertyKind.Primitive || propertyKind == PropertyKind.Complex)
                {
                    MapStructuralProperty(complexType, property, propertyKind, isCollection);
                }
                else
                {
                    // navigation property in a complex type ?
                    if (!isCollection)
                    {
                        if (mappedType == null)
                        {
                            // the user told nothing about this type and this is the first time we are seeing this type.
                            // complex types cannot contain entities. So, treat it as complex property.
                            complexType.AddComplexProperty(property);
                        }
                        else
                        {
                            if (_explicitlyAddedTypes.Contains(mappedType))
                            {
                                // user told us that this an entity type.
                                throw Error.InvalidOperation(SRResources.ComplexTypeRefersToEntityType, complexType.ClrType.FullName, mappedType.ClrType.FullName, property.Name);
                            }
                            else
                            {
                                // we tried to be over-smart earlier and made the bad choice. so patch up now.
                                ReconfigureEntityTypesAsComplexType(new IEntityTypeConfiguration[] { mappedType as IEntityTypeConfiguration });
                                complexType.AddComplexProperty(property);
                            }
                        }
                    }
                    else
                    {
                        throw Error.NotSupported(SRResources.CollectionPropertiesNotSupported, property.Name, property.ReflectedType.FullName);
                    }
                }
            }
        }