Posts

Showing posts with the label Nhibernate

Code Snippet: Set default database schema in Nhibernate SessionFactory

1: //Setup oracle database connection and connection pool 2: public class OracleConnectionManager 3: { 4: private static string _userName; 5: private static string _password; 6: 7: public OracleConnectionManager(string userName, string password) 8: { 9: _userName = userName; 10: _password = password; 11: } 12: 13: private static ISessionFactory _sessionFactory; 14: private static ISessionFactory SessionFactory { get 15: { 16: if(_sessionFactory == null) 17: { 18: var connectionString = DatabaseConnections.GetOracleConnectionsString(_userName,_password); 19: 20: //Nhibernate Oracle database configuration 21: var configuration = new Configuration(); 22: configuration.DataBaseIntegration(db => 23: { 24: db.ConnectionProvider<NHibernate.Connection.DriverConnectionProvider>(...

Nhibernate criteria API - select from multiple tables

If you ever worked with relational databases then higher chances are you already worked with sub queries. Some time while working with Nhibernate you get yourself into some situation where you need sub query to do some lifting for you. In NHibernate criteria API you can do the sub query using DetachedCriteria  and  Subqueries  classes. As the name suggests  DetachedCriteria  helps you define your sub query criteria while  Subqueries  class help you create sub query criterion object using detached criteria object. In order to demonstrate sub query implementation lets consider an example. Suppose we have three entities Order, OrderItem and Product where one order can more have more then one order items while one order item may be linked to a product. If we need to do a query where we need to list all those order items which are linked to products and have price greater then $100. Also the products must be the ones marked as special in system. The SQL ...