/// <summary>
        /// Gets the name of the column for the property from the metadata.
        /// Set nestedProperty for the property of a complex type to lookup.
        /// </summary>
        /// <param name="mappingFragment">EF metadata for finding mappings.</param>
        /// <param name="edmProperty">The of the model to find the column for (for simple types), or for complex types this is the containing complex type.</param>
        /// <param name="nestedProperty">Only required to map complex types. The property of the complex type to find the column name for.</param>
        /// <returns>The column name for the property</returns>
        /// <exception cref="EnumGeneratorException">
        /// </exception>
        private static string GetColumnName(StructuralTypeMapping mappingFragment, EdmProperty edmProperty, EdmProperty nestedProperty = null)
        {
            var propertyMapping = GetPropertyMapping(mappingFragment, edmProperty);

            if (nestedProperty != null)
            {
                var complexPropertyMapping = propertyMapping as ComplexPropertyMapping;
                if (complexPropertyMapping == null)
                {
                    throw new EnumGeneratorException(string.Format(
                                                         "Failed to cast complex property mapping for {0}.{1} to ComplexPropertyMapping", edmProperty, nestedProperty));
                }
                var complexTypeMappings = complexPropertyMapping.TypeMappings;
                if (complexTypeMappings.Count() != 1)
                {
                    throw new EnumGeneratorException(string.Format(
                                                         "{0} complexPropertyMapping TypeMappings found for property {1}.{2}", complexTypeMappings.Count(), edmProperty, nestedProperty));
                }
                var complexTypeMapping = complexTypeMappings.Single();
                var propertyMappings   = complexTypeMapping.PropertyMappings.Where(pm => pm.Property.Name == nestedProperty.Name).ToList();
                if (propertyMappings.Count() != 1)
                {
                    throw new EnumGeneratorException(string.Format(
                                                         "{0} complexMappings found for property {1}.{2}", propertyMappings.Count(), edmProperty, nestedProperty));
                }

                propertyMapping = propertyMappings.Single();
            }

            return(GetColumnNameFromPropertyMapping(edmProperty, propertyMapping));
        }
        private static PropertyMapping GetPropertyMapping(StructuralTypeMapping mappingFragment, EdmProperty edmProperty)
        {
            var matches = mappingFragment.PropertyMappings.Where(m => m.Property.Name == edmProperty.Name).ToList();

            if (matches.Count() != 1)
            {
                throw new EnumGeneratorException(string.Format(
                                                     "{0} matches found for property {1}", matches.Count(), edmProperty));
            }
            var match = matches.Single();

            return(match);
        }