/// <summary> /// ����nh���� /// </summary> /// <param name="facilityConfiguration"></param> /// <returns></returns> public NHibernate.Cfg.Configuration GetConfiguration(IConfiguration facilityConfiguration) { var configuration = new DefaultConfigurationBuilder().GetConfiguration(facilityConfiguration); //����ӳ�� var assemblies = facilityConfiguration.Children["assemblies"]; assemblies.Children.ForEach(o => configuration.AddMappingsFromAssembly(Assembly.Load(o.Value))); //����������� var fluent = FluentNHibernate.Cfg.Fluently.Configure(configuration); var classes = facilityConfiguration.Children["classes"]; if (classes == null) return configuration; classes.Children.ForEach(o => { var m = new PersistenceModel(); var type = Type.GetType(o.Value, false); if (type == null) throw new Exception("�Ҳ�������" + o.Value + "����ȷ���Ƿ����ø��������ڵij���"); m.Add(type); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { m.WriteMappingsTo(writer); writer.Flush(); stream.Seek(0, 0); configuration.AddInputStream(stream); } }); return configuration; }
public static void MyClassInitialize(TestContext testContext) { try { IPersistenceConfigurer persistenceConfigurer = MySQLConfiguration.Standard.ConnectionString(c => c.Is("Server=localhost;Database=basicproject;User ID=root;Password=1234")).ShowSql(); // initialize nhibernate with persistance configurer properties Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration()); // add mappings definition to nhibernate configuration var persistenceModel = new PersistenceModel(); persistenceModel.AddMappingsFromAssembly(Assembly.Load("BasicProject.NHibernateInfra.Implementation")); persistenceModel.Configure(cfg); // set session factory field which is to be used in tests _sessionFactory = cfg.BuildSessionFactory(); } catch (ReflectionTypeLoadException ex) { StringBuilder sb = new StringBuilder(); foreach (Exception exSub in ex.LoaderExceptions) { sb.AppendLine(exSub.Message); if (exSub is FileNotFoundException) { FileNotFoundException exFileNotFound = exSub as FileNotFoundException; if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); } string errorMessage = sb.ToString(); //Display or log the error based on your application. } }
public static Configuration AddMappingsFromAssembly(this Configuration configuration, Assembly assembly) { var models = new PersistenceModel(); models.AddMappingsFromAssembly(assembly); models.Configure(configuration); return configuration; }
public ISessionSource CreateSessionSource(PersistenceModel model) { var properties = GetProperties(); var source = new SessionSource(properties, model); create_schema_if_it_does_not_already_exist(source); return source; }
protected void Initialize(Configuration nhibernateConfig, PersistenceModel model) { if( model == null ) throw new ArgumentNullException("model", "Model cannot be null"); Configuration = nhibernateConfig; model.Configure(Configuration); SessionFactory = Configuration.BuildSessionFactory(); dialect = Dialect.GetDialect(Configuration.Properties); }
private NHibernate.Cfg.Configuration buildNewConfig() { var config = new NHibernate.Cfg.Configuration(); buildConfig().ConfigureProperties(config.SetProperty("config-source", this.GetType().FullName)); config.EventListeners.PreInsertEventListeners = new NHibernate.Event.IPreInsertEventListener[] { new TimeStampEventListener() }; config.EventListeners.PreUpdateEventListeners = new NHibernate.Event.IPreUpdateEventListener[] { new TimeStampEventListener() }; var model = new PersistenceModel(); modifyPersistenceModel(model); model.Configure(config); return addConfig(config); }
public FluentConfigurer ExportHbmMappings() { if (!Directory.Exists(ExportDirectory)) { Directory.CreateDirectory(ExportDirectory); } var persistenceModel = new PersistenceModel(); persistenceModel.AddMappingsFromAssembly(Assembly.GetAssembly(typeof(FluentConfigurer))); persistenceModel.Configure(Configuration); persistenceModel.WriteMappingsTo(ExportDirectory); return this; }
public MySessionSource(IDictionary<string, string> properties, PersistenceModel model) { if(model == null) throw new ArgumentException("Model cannot be null!"); _configuration = new Configuration(); if (properties == null) _configuration.Configure(); else _configuration.AddProperties(properties); Model = model; model.Configure(_configuration); _sessionFactory = _configuration.BuildSessionFactory(); }
private static void buildModel() { // initialize persistance configurer IPersistenceConfigurer persistenceConfigurer = getPersistenceConfigurer(); // initialize nhibernate with persistance configurer properties cfg = persistenceConfigurer.ConfigureProperties(new Configuration()); // add mappings definition to nhibernate configuration var persistenceModel = new PersistenceModel(); persistenceModel.addMappingsFromAssembly(typeof(ModelBuilder).Assembly); persistenceModel.Conventions.GetPrimaryKeyName = x => x.Name; persistenceModel.Conventions.GetForeignKeyName = x => x.Name; persistenceModel.Configure(cfg); //Mix mode, this line allows us to append config settings to our configuration //instance from .config files (web.config,app.config) // or any other "traditional" (xml based) approach. //NOTE: If you are going to go with full Fluent configuration, you should remove the line below cfg.Configure(); }
/// <summary> /// Returns the FluentNHibernate Sqlite configuration data /// </summary> /// <param name="assembly">The assembly containing the mappings</param> /// <returns>SQLite configuration</returns> IPersistenceConfigurer IDatabaseConfiguration.Create(Assembly assembly) { SQLiteConfiguration config = new SQLiteConfiguration() .UsingFile(m_strDbPath) .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu") .ShowSql(); if (!File.Exists(m_strDbPath)) { PersistenceModel pm = new PersistenceModel(); pm.AddMappingsFromAssembly(assembly); SessionSource ss = new SessionSource(config.ToProperties(), pm); ss.BuildSchema(); ss = null; } return config; }
public void Setup() { FluentConfiguration configuration = Fluently.Configure() .Database(SQLiteConfiguration.Standard .InMemory() .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu") .ShowSql()); PersistenceModel pm = new PersistenceModel(); pm.AddMappingsFromAssembly(typeof(Artist).Assembly); SingleConnectionSessionSourceForSQLiteInMemoryTesting ss = new SingleConnectionSessionSourceForSQLiteInMemoryTesting(configuration.BuildConfiguration().Properties, pm); ss.BuildSchema(); Session = ss.CreateSession(); m_uow = new UnitOfWork(Session); SetupContext(Session); m_uow.Commit(); Session.Clear(); }
public ConfigurationSource(IEnumerable<IConfigurationModifier> registries) { _registries = registries; _model = new Lazy<PersistenceModel>(() => { var model = new PersistenceModel(); _registries.Each(r => r.Configure(model)); return model; }); _configuration = new Lazy<Configuration>(() => { var configuration = new Configuration(); _registries.Each(r => r.ApplyProperties(configuration)); _model.Value.Configure(configuration); _registries.Each(r => r.Configure(configuration)); return configuration; }); }
public SessionSource(IDictionary<string, string> properties, PersistenceModel model) { Initialize(new Configuration().AddProperties(properties), model); }
public SessionSource(PersistenceModel model) { Initialize(new Configuration().Configure(), model); }
private void InitSessionFactory() { IPersistenceConfigurer persistenceConfigurer = MsSqlConfiguration .MsSql2005 .ConnectionString(c => c.FromConnectionStringWithKey("CxRomosConnStr")) .UseReflectionOptimizer().ShowSql(); Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration()); var persistenceModel = new PersistenceModel(); persistenceModel.AddMappingsFromAssembly(Assembly.Load("CxRomos.Core")); persistenceModel.Configure(cfg); _sessionFactory = cfg.BuildSessionFactory(); }
private void InitSessionFactory() { IPersistenceConfigurer persistenceConfigurer = MsSqlConfiguration .MsSql2005 .ConnectionString(c => c.FromConnectionStringWithKey("TimeTracker.Reporting.Properties.Settings.TimeTrackerConnStr")); Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration()); var persistenceModel = new PersistenceModel(); persistenceModel.AddMappingsFromAssembly(Assembly.Load("TimeTracker.Core")); persistenceModel.Configure(cfg); sessionFactory = cfg.BuildSessionFactory(); }
private ISessionFactory CreateConfiguration() { IPersistenceConfigurer persistenceConfigurer = MsSqlConfiguration.MsSql2008.ConnectionString (c => c.FromConnectionStringWithKey("RepositoryPatternDemo")); Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration()); var persistenceModel = new PersistenceModel(); var assembly = typeof(BlogPostMap).Assembly; persistenceModel.AddMappingsFromAssembly(assembly); persistenceModel.Configure(cfg); return cfg.BuildSessionFactory(); }
public MySessionSource(PersistenceModel model) : this(null, model) { }
protected abstract void modifyPersistenceModel(PersistenceModel model);