Git Product home page Git Product logo

nhibernate-x-factories's Introduction

NHibernate X-Factories v5.1.0

NHibernate X-Factories allow you to combine multiple .cfg.xml into one. X-Factories does this by allowing each session-factory to be named and referred to individually by name. This gives a cleaner and less verbose configuration for using NHiberate between multiple databases.

Setup

Setup is really quite simple.

  1. Install via NuGet.
  2. The nhibernate-configuration-x-factories.xsd scheme may be included to a Project or Solution and is available in the NuGet package root folder.
  3. Change the xmlns attribute of the hibernate-configuration element in your .cfg.xml to urn:nhibernate-configuration-2.2-x-factories.
  4. Change hibernate-configuration element to hibernate-configuration-x-factories.
  5. Give the session-factory element a name and create as many session-factory elements as you like.

Usage

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration-x-factories xmlns="urn:nhibernate-configuration-2.2-x-factories">
	
	<session-factory name="Development">
		<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
		<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
		<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
		<property name="connection.connection_string">
			Server=dsql01;DataBase=dbDev;uid=nhDeveloper;pwd=pass1234
		</property>

		<property name="show_sql">true</property>

		<mapping assembly="DataLayer" />
	</session-factory>
	
	<session-factory name="Production">
		<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
		<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
		<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
		<property name="connection.connection_string">
			Server=psql02;DataBase=dbDev;uid=nhDeveloper;pwd=pass5678
		</property>
		
		<property name="show_sql">false</property>

		<mapping assembly="DataLayer" />
	</session-factory>
	
</hibernate-configuration-x-factories>
using NHibernate;
using NHibernate.Cfg;
using NHibernate.XFactories;

NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config
	.Configure(HostingEnvironment.MapPath("~/nhibernate.cfg.xml"), "Development")
	.BuildSessionFactory();

Support

Required

Optional

License

Licensed under the MIT.

nhibernate-x-factories's People

Contributors

roydukkey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nhibernate-x-factories's Issues

Prepare schema for future release of NHibernate.

  1. NH-2611 - Support for a user defined query provider [1]
  2. NH-3619 - Make default value of FlushMode configurable [2]
  3. NH-3499 - Add query.query_model_rewriter_factory to nhibernate configuration schema [3]
  4. NH-3783 - Add order_updates to nhibernate configuration schema [4]
  5. NH-3895 - Allow OdbcDriver to set explicit scale for DbType.DateTime when needed [5]

Failed to connect to SQL2000

I need to access 2 sql dbs, one is MS SQL 2014,I named it ACDS and the 2nd is an old ms sql2000,i named it EF.
I put everything into ,the nhibernate.cfg.xml, run from my own pc,it works.
Then i publish the service code to an winserver 2008,it failed to access the EF db,the error message looks like:
An exception of type 'System.Data.SqlClient.SqlException' occurred in NHibernate.dll but was not handled in user code.
it says failed to locate the db server(provider: SQL Network Interfaces, error: 26).

But the ACDS db works fine at the same time.
Then i move back to my PC,and change the configuration as the [Configuration from Web.Config] told,this time it failed with same error (provider: SQL Network Interfaces, error: 26).

If i move the config data back to the nhibernate.cfg.xml file from the web.config,every thing works fine in my pc.

App.config

Hi,
would like to use this from App.config (....exe.config) for a Windows Service Application. Have tried but do not get it working. I followed your wiki article "Configuration from Web.Config" with using App.config instead of Web.config. But it does not compile because NHibernate.Cfg.Configuration.Configure does not have a version with two String parameters. I'm using NHibernate 3.4.0.0.
Thank you very much for any help, Martin

Invalid XML parsing

The provided source has the following block:

//XmlElement root = doc.DocumentElement;
XmlNode nhibernateNode = root.SelectSingleNode("descendant::nhibernate:hibernate-configuration", namespaceMgr);

In the case of the sample XML you provided, nhibernateNode is null with the above query. Querying for the node directly from doc, instead of doc.DocumentElement does work.

XmlNode nhibernateNode = doc.SelectSingleNode("descendant::nhibernate:hibernate-configuration", namespaceMgr);

Schema warns about element it shouldn't access.

The nhibernate-configuration-x-factories.xsd throws warning to elements outside of the <hibernate-configuration-x-factories /> element.

Example:

The global element 'urn:nhibernate-configuration-2.2-x-factories:{...}' has already been declared.

Create package for Nuget

  • Change namespace to NHibernate.XFactories
  • Create solution and project
  • Register project on Nuget.org
  • Update documentation to remove independent installation instructions.
  • Remove GPL license
  • Add MIT LICENSE file

Doesn't work on Mono.

It appears that Mono handles XML a little differently and causes exception to be thrown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.