Exemple #1
0
        public static EntityMetadata GetEntityMetadata <T>(this DbContext dbContext)
        {
            MetadataWorkspace metadataWorkspace      = dbContext.GetObjectContext().MetadataWorkspace;
            MappingFragment   mappingFragment        = metadataWorkspace.GetMapping <T>();
            EntityType        storageSpaceEntityType = mappingFragment.StoreEntitySet.ElementType;

            EntityMetadata entityMetadata = new EntityMetadata
            {
                TempTableName = "##TEMP_" + Guid.NewGuid().ToString().Replace('-', '_'),
                Type          = typeof(T),
                TableName     = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo("en-us")).Pluralize(storageSpaceEntityType.Name),
                Properties    = storageSpaceEntityType.Properties.Select(x => new EntityProperty
                {
                    ColumnName    = x.Name,
                    IsDbGenerated = x.IsStoreGeneratedIdentity || x.IsStoreGeneratedComputed,
                    SqlServerType = GetSqlServerType(x),
                    IsNullable    = x.Nullable,
                    PropertyName  = GetPropertyName(mappingFragment, x)
                }).ToList()
            };

            return(entityMetadata);
        }