本文整理汇总了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;
}
}
示例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();
}
示例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;
}
}
示例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!");
}
示例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);
}
}
}
示例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);
}
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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();*/
}