Exemple #1
0
        static IEnumerable <Type> CreateEntitiesTypes(DbConnection existingConnection)
        {
            using (MetadataInitializationContext context = new MetadataInitializationContext(existingConnection, false))
            {
                DynamicAssemblyBuilder assemblyBuilder = new DynamicAssemblyBuilder();

                var entities = context.Entities.Include(c => c.Attributes)
                               .Include(c => c.Listeners)
                               .Include(c => c.Proxies)
                               .Include("Attributes.Type")
                               .Include(c => c.ManyToOneRelationships)
                               .Include(c => c.OneToManyRelationships).ToArray();

                var types = assemblyBuilder.BuildTypes(entities).ToArray();

                assemblyBuilder.SaveAssembly();

                return(types);
            }
        }