当前位置: 首页>>代码示例>>C#>>正文


C# NHibernate.Cfg.Configuration.AddAssembly方法代码示例

本文整理汇总了C#中NHibernate.Cfg.Configuration.AddAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.Cfg.Configuration.AddAssembly方法的具体用法?C# NHibernate.Cfg.Configuration.AddAssembly怎么用?C# NHibernate.Cfg.Configuration.AddAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.Cfg.Configuration的用法示例。


在下文中一共展示了NHibernate.Cfg.Configuration.AddAssembly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

        /// <summary>
        /// Builds the session factory with the given properties. Database is updated if updateSchema is set
        /// </summary>
        /// <param name="nhibernateProperties"></param>
        /// <param name="updateSchema"></param>
        /// <returns></returns>
        public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema)
        {
            var model = Create.SagaPersistenceModel(typesToScan);
            var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct();

            var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties);

            foreach (var assembly in scannedAssemblies)
            {
                nhibernateConfiguration.AddAssembly(assembly);
            }

            var fluentConfiguration = Fluently.Configure(nhibernateConfiguration)
                                        .Mappings(m => m.AutoMappings.Add(model));

            ApplyDefaultsTo(fluentConfiguration);

            if (updateSchema)
            {
                UpdateDatabaseSchemaUsing(fluentConfiguration);
            }

            try
            {
                return fluentConfiguration.BuildSessionFactory();
            }
            catch (FluentConfigurationException e)
            {
                if (e.InnerException != null)
                    throw new ConfigurationErrorsException(e.InnerException.Message, e);

                throw;
            }
        }
开发者ID:togakangaroo,项目名称:NServiceBus,代码行数:40,代码来源:SessionFactoryBuilder.cs

示例2: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            var configuration = new NHibernate.Cfg.Configuration();
            configuration.Configure();
            configuration.AddAssembly(typeof(doCS.Models.Project).Assembly);
            SessionFactory = configuration.BuildSessionFactory();

            // Build up your application container and register your dependencies.
            var builder = new ContainerBuilder();
            builder.RegisterControllers(System.Reflection.Assembly.GetExecutingAssembly());
            builder.Register(x => SessionFactory.OpenSession()).As<ISession>().HttpRequestScoped();
            builder.RegisterType<doCS.Web.Helpers.Implimentation.ProjectContext>().As<doCS.Web.Helpers.IProjectContext>().HttpRequestScoped();

            //register extractor helpers
            builder.RegisterType<doCS.Web.Helpers.Implimentation.Extractor.ExtractorHelper>().As<doCS.Web.Helpers.IExtractorHelper>().HttpRequestScoped();
            builder.RegisterType<doCS.Web.Helpers.Implimentation.Extractor.ProjectUpdaterProvider>().InstancePerDependency();

            //register extractor dependencies
            builder.RegisterType<doCS.Extractor.Implementation.Extractor>().As<doCS.Extractor.IExtractor>().HttpRequestScoped();
            builder.RegisterType<doCS.Extractor.Implementation.DllExtractor>();
            builder.RegisterType<doCS.Extractor.Implementation.XmlExtractor>();

            //register view helpers
            builder.RegisterType<doCS.Web.ViewHelpers.XmlDocumentationHelper>();

            _containerProvider = new ContainerProvider(builder.Build());
            ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(ContainerProvider));

            SetupAutoMapper();
        }
开发者ID:flukus,项目名称:doCS,代码行数:34,代码来源:Global.asax.cs

示例3: Build

        /// <summary>
        /// Builds the session factory with the given properties. Database is updated if updateSchema is set
        /// </summary>
        /// <param name="nhibernateProperties"></param>
        /// <param name="updateSchema"></param>
        /// <returns></returns>
        public ISessionFactory Build(IDictionary<string, string> nhibernateProperties, bool updateSchema)
        {
            var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct();

              var nhibernateConfiguration = new Configuration().SetProperties(nhibernateProperties);

              foreach (var assembly in scannedAssemblies)
            nhibernateConfiguration.AddAssembly(assembly);

              var mapping = new SagaModelMapper(typesToScan.Except(nhibernateConfiguration.ClassMappings.Select(x => x.MappedClass)));

              HackIdIntoMapping(mapping);

              nhibernateConfiguration.AddMapping(mapping.Compile());

              ApplyDefaultsTo(nhibernateConfiguration);

              if (updateSchema)
            UpdateDatabaseSchemaUsing(nhibernateConfiguration);

              try
              {
            return nhibernateConfiguration.BuildSessionFactory();
              }
              catch (Exception e)
              {
            if (e.InnerException != null)
              throw new ConfigurationErrorsException(e.InnerException.Message, e);

            throw;
              }
        }
开发者ID:kostaswonga,项目名称:NServiceBus,代码行数:38,代码来源:SessionFactoryBuilder.cs

示例4: Main

        public static void Main(string[] args)
        {
            IList<Product> products;

            // Don't need to use schema export because of the hbm2dll property.
            var cfg = new NHibernate.Cfg.Configuration();
            cfg.Configure();
            // ensure that mapping hbm.xml file is loaded
            cfg.AddAssembly(typeof(MainClass).Assembly);

            Product p = new Product() {Name="Captains of Crush Gripper #1", Category="fitness" };

            ISessionFactory factory =
                cfg.BuildSessionFactory();

            using (ISession session = factory.OpenSession())
            {
                session.Save(p);
                session.Flush();

              	ICriteria sc = session.CreateCriteria<Product>();
              	products = sc.List<Product>();
                Console.WriteLine(products[0].Name);
              	session.Close();
            }
            factory.Close();

            Console.WriteLine( products.Count );

            Console.WriteLine ("Hello World!");
        }
开发者ID:I82Much,项目名称:Mono-NHibernate,代码行数:31,代码来源:Main.cs

示例5: Main

        static void Main(string[] args)
        {
            var configuration = new Configuration()
                .SetProperty(Environment.ReleaseConnections, "on_close")
                .SetProperty(Environment.Dialect, typeof(MsSql2008Dialect).AssemblyQualifiedName)
                .SetProperty(Environment.ConnectionDriver, typeof(SqlClientDriver).AssemblyQualifiedName)
                .SetProperty(Environment.ConnectionString, ConfigurationManager.ConnectionStrings["db"].ToString())
                .SetProperty(Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName);

            configuration.AddAssembly(typeof(Blog).Assembly);

            SessionManager.Init(configuration, new SingleSessionStorage());

            var session = SessionManager.Current;

            new SchemaExport(configuration).Execute(false, true, false, session.Connection, null);

            if (args.Count() > 0)
            {
                if (string.Compare(args[0], "/DEMODATA", StringComparison.InvariantCultureIgnoreCase) == 0)
                {

                    DemoData.SetupData(session);
                }
            }
        }
开发者ID:hhariri,项目名称:MetaBlogAPI,代码行数:26,代码来源:Program.cs

示例6: InitSessionFactory

        public void InitSessionFactory()
        {
            try
            {
                string connectionString = "Data Source=Pets.sdf";
                string owner = String.Empty;

                NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
                configuration.Properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect");
                configuration.Properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver");
                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);

                configuration.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
                configuration.Properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
                configuration.Properties.Add("connection.connection_string", connectionString);
                configuration.Properties.Add("show_sql", "true");
                configuration.AddAssembly("DataDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

                //ToDo :: Add more entity assembly keys if you nHibernate stuff crashes and you don't know why...

                _sessionFactory = configuration.BuildSessionFactory();
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("Creating the session factory failed with {0}", ex.Message);
            }
        }
开发者ID:ssdug,项目名称:2013-April-Florey,代码行数:27,代码来源:MySessionFactory.cs

示例7: GetSessionFactory

        public static NHibernate.ISessionFactory GetSessionFactory(
            string connectionString, List<String> DllNames)
        {
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            // set provider & driver properties
            cfg.Properties.Add(
            "connection.provider",
                "NHibernate.Connection.DriverConnectionProvider");

            cfg.Properties.Add(
            "connection.driver_class",
                "NHibernate.Driver.SQLite20Driver");

            cfg.Properties.Add(
            "dialect",
                "NHibernate.Dialect.SQLiteDialect");

            cfg.Properties.Add(
            "max_fetch_depth","-1"); // allows for unlimited outer joins (recommeded value is maximum 4

            cfg.Properties.Add(
            "connection.connection_string",
                 ConfigurationManager.ConnectionStrings[connectionString].ConnectionString);

            cfg.Properties.Add("connection.isolation", "ReadCommitted");
            cfg.Properties.Add("query.substitutions", "true 1, false 0");

            // here we add all the needed assemblies that contain mappings or objects
            foreach (String assemblyName in DllNames)
                cfg.AddAssembly(System.Reflection.Assembly.Load(assemblyName));

            return cfg.BuildSessionFactory();
        }
开发者ID:zorky,项目名称:mymedias,代码行数:33,代码来源:NHIbernateSessionFactory.cs

示例8: GetSessionFactory

 public static ISessionFactory GetSessionFactory()
 {
     var configuration = new NHibernate.Cfg.Configuration();
     configuration.Configure();
     configuration.AddAssembly(typeof(SessionFactoryFactory).Assembly.GetName().Name);
     log4net.Config.XmlConfigurator.Configure();
     var sessionFactory = configuration.BuildSessionFactory();
     return sessionFactory;
 }
开发者ID:lucidcoding,项目名称:EdaCalendarExample,代码行数:9,代码来源:SessionFactoryFactory.cs

示例9: Main

 /// <summary>
 /// The main method for the application.
 /// </summary>
 /// <param name="args">
 /// The command-line arguments.
 /// </param>
 public static void Main(string[] args)
 {
     NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
     configuration.Configure();
     configuration.AddAssembly(typeof(Manufacturer).Assembly);
     new SchemaExport(configuration).Execute(true, false, true);
     Application.Init();
     MainWindow win = new MainWindow();
     win.Show();
     Application.Run();
 }
开发者ID:karldickman,项目名称:BikeLog,代码行数:17,代码来源:Program.cs

示例10: InitialiseDB

        /// <summary>
        /// Setup NHibernate and connect to the database
        /// </summary>
        /// <returns></returns>
        private void InitialiseDB()
        {
            //
            // Setup database connection
            //
            // (1) Configure NHibernate 
            //
            // - NB. We should be able to do this from a configuration object
            // - Also there may be versioning issues with log4net ?
            //
            //            string strDirectory = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName;           
            try
            {
                Logger.Debug("Bringing up NHibernate");
                NhibernateCfg = new NHibernate.Cfg.Configuration();

                if (useDevDatabaseToolStripMenuItem.Checked)
                {
                    if (!string.IsNullOrEmpty(Globals.DevelopmentDBURI))
                    {
                        Logger.Warn("*** OVERRIDING WITH DEV DATABASE ***");
                        NhibernateCfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, Globals.DevelopmentDBURI);
                    }
                    else
                    {
                        throw new ArgumentException("*** NO DEV DATABASE DEFINED ***");
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(Globals.ProductionDBURI))
                    {
                        NhibernateCfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, Globals.ProductionDBURI);
                    }
                    else
                    {
                        throw new ArgumentException("*** NO PRODUCTION DATABASE DEFINED ***");
                    }                    
                }

                NhibernateCfg.AddAssembly("DynamicDevices.Testing.DAO");

                Logger.Debug("Now building external DB session factory");
                Nhibernatefactory = NhibernateCfg.BuildSessionFactory();

                Session = Nhibernatefactory.OpenSession();
            }
            catch (Exception e)
            {
                Logger.Warn("Exception bringing up NHibernate: " + e.Message);
            }
            return;
        }
开发者ID:DynamicDevices,项目名称:dta,代码行数:57,代码来源:frmMain.cs

示例11: CreateConfiguration

 public static NHibernate.Cfg.Configuration CreateConfiguration()
 {
     IDictionary<string, string> props = new Dictionary<string, string>();
     props["connection.driver_class"] = "NHibernate.Driver.SQLite20Driver";
     props["dialect"] = "NHibernate.Dialect.SQLiteDialect";
     props["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
     props["connection.connection_string"] =
         string.Format(@"Data Source=|DataDirectory|\{0};Version=3;New=True", "NHibernate.Generics.Test.SQLite");
     NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
     cfg.Properties = props as IDictionary;
     cfg.AddAssembly(Assembly.GetExecutingAssembly());
     return cfg;
 }
开发者ID:rcarrillopadron,项目名称:nhibernategenerics,代码行数:13,代码来源:GenericWrapperAccessorTests.cs

示例12: BuildNHibernateConfiguration

        private NHibernate.Cfg.Configuration BuildNHibernateConfiguration(string connectionString)
        {
            IDictionary<string, string> configPropertyTable = new Dictionary<string, string>(this.StaticConfigPropertyTable);
            configPropertyTable[NHibernateProviderManager.ConnectionStringKey] = connectionString;

            var config = new NHibernate.Cfg.Configuration().SetProperties(configPropertyTable);

            foreach (var assemblyName in this.XmlMappingAssemblyNames)
            {
                config.AddAssembly(assemblyName);
            }

            return config;
        }
开发者ID:EvgeniyProtas,项目名称:servicestack,代码行数:14,代码来源:NHibernateProviderManagerFactory.cs

示例13: configSession

        public static void configSession()
        {
            //gets the connection string data associated with this db
            string dsn = ConfigurationManager.ConnectionStrings[connectionString].ConnectionString;
            config = new NHibernate.Cfg.Configuration();

            config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSqlCeDialect");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
            config.SetProperty("hibernate.show_sql", "true");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, dsn);

            ///important to add assembly, which is the name of the app or project usually;
            config.AddAssembly("OnBudgetApp");
            SessionFactory = config.BuildSessionFactory();
        }
开发者ID:Fabii23,项目名称:dotnetrepo,代码行数:16,代码来源:HibHelper.cs

示例14: Settings

        /// <summary>
        /// Static constructor
        /// Inintializes default settings
        /// </summary>
        static Settings()
        {
            _connectionString = "";
            _isDebug = false;

            Configuration cfg = new Configuration();
            IDictionary section = ConfigurationManager.GetSection(NhibernateSectionName) as IDictionary;
            if (section == null)
            {
                throw new NHibernateSectionLoadException();
            }
            cfg.AddProperties(section);
            cfg.AddAssembly(typeof(Settings).Assembly);

            _sessionFactory = cfg.BuildSessionFactory();
        }
开发者ID:3agrey,项目名称:pbc,代码行数:20,代码来源:Settings.cs

示例15: CreateNhSessionFactory

        /// <summary>
        /// Creates NHibernate Session Factory.
        /// </summary>
        /// <returns>NHibernate Session Factory</returns>
        private static ISessionFactory CreateNhSessionFactory(IKernel kernel, CreationContext context)
        {
            NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration().Configure();            
            cfg.AddAssembly("Konekti.Model");

            // update schema or create one if not exist
            new SchemaUpdate(cfg).Execute(false, true);

            return cfg.BuildSessionFactory();

            /*string connStr = ConfigurationManager.ConnectionStrings["Konekti"].ConnectionString;

            return Fluently.Configure()
                .Database(MySQLConfiguration.Standard.ConnectionString(connStr))
                .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(MenuGroup))))
                .BuildSessionFactory();*/
        }
开发者ID:masalinas,项目名称:konekti.net,代码行数:21,代码来源:KonektiDependencyInstaller.cs


注:本文中的NHibernate.Cfg.Configuration.AddAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。