public void Generate(IStreamProvider streamProvider) { GenerationContext ctx = new GenerationContext(); ctx.Dialect = GetDialect(); ctx.Model = new MappingModelImpl(); IDriver driver = GetDriver(); try { using (IDbConnection connection = driver.CreateConnection()) { DbConnection dbConn = connection as DbConnection; if (null == dbConn) { throw new Exception("Can't convert connection provided by driver to DbConnection"); } connection.ConnectionString = cfg.connectioninfo.connectionstring; connection.Open(); ctx.Schema = ctx.Dialect.GetDataBaseSchema(dbConn); ctx.Configuration = cfg; ctx.Connection = dbConn; ctx.TableExceptions = new TableExceptions(cfg); ctx.NamingStrategy = TypeFactory.Create <INamingStrategy>(cfg.namingstrategy); log.Info("Retrieving working table list"); ctx.FilteredTables.AddRange(TableEnumerator.GetInstance(ctx.Schema)); foreach (IMetadataStrategy strategy in metaStrategies) { strategy.Process(ctx); } } foreach (var clazz in ctx.Model.GetEntities()) { TextWriter target = streamProvider.GetTextWriter(clazz.name); hibernatemapping mapping = new hibernatemapping(); mapping.Items = new object[] { clazz }; if (!string.IsNullOrEmpty(cfg.entitiesnamespace)) { mapping.@namespace = cfg.entitiesnamespace; } if (!string.IsNullOrEmpty(cfg.entitiesassembly)) { mapping.assembly = cfg.entitiesassembly; } XmlSerializer ser = new XmlSerializer(typeof(hibernatemapping)); XmlSerializerNamespaces empty = new XmlSerializerNamespaces(); empty.Add(string.Empty, "urn:nhibernate-mapping-2.2"); ser.Serialize(target, mapping, empty); target.Flush(); target.Close(); streamProvider.EndWrite(); } } catch (Exception e) { throw e; } }
public void Generate(IStreamProvider streamProvider) { GenerationContext ctx = new GenerationContext(); ctx.Dialect = GetDialect(); ctx.Model = new MappingModelImpl(); IDriver driver = GetDriver(); try { using (IDbConnection connection = driver.CreateConnection()) { DbConnection dbConn = connection as DbConnection; if (null == dbConn) throw new Exception("Can't convert connection provided by driver to DbConnection"); connection.ConnectionString = cfg.connectioninfo.connectionstring; connection.Open(); ctx.Schema = ctx.Dialect.GetDataBaseSchema(dbConn); ctx.Configuration = cfg; ctx.Connection = dbConn; ctx.TableExceptions = new TableExceptions(cfg); ctx.NamingStrategy = TypeFactory.Create<INamingStrategy>(cfg.namingstrategy); log.Info("Retrieving working table list"); ctx.FilteredTables.AddRange(TableEnumerator.GetInstance(ctx.Schema)); foreach (IMetadataStrategy strategy in metaStrategies) strategy.Process(ctx); } foreach (var clazz in ctx.Model.GetEntities()) { TextWriter target = streamProvider.GetTextWriter(clazz.name); hibernatemapping mapping = new hibernatemapping(); mapping.Items = new object[] { clazz }; if (!string.IsNullOrEmpty(cfg.entitiesnamespace)) mapping.@namespace = cfg.entitiesnamespace; if (!string.IsNullOrEmpty(cfg.entitiesassembly)) mapping.assembly = cfg.entitiesassembly; XmlSerializer ser = new XmlSerializer(typeof(hibernatemapping)); XmlSerializerNamespaces empty = new XmlSerializerNamespaces(); empty.Add(string.Empty, "urn:nhibernate-mapping-2.2"); ser.Serialize(target, mapping,empty); target.Flush(); target.Close(); streamProvider.EndWrite(); } } catch (Exception e) { throw e; } }