2. Create the Nhibernatehelper help class to generate the Sessionfactory

Source: Internet
Author: User

Connect to the previous article using the Fluentnhibemate operations database, adding maps to the database

Http://www.cnblogs.com/fzxiaoyi/p/8443586.html

in the Model file to create a new class Nhibernatehelper

Write the following code:

Using nhibernate;using system;using system.collections.generic;using system.linq;using System.Text;using System.threading.tasks;namespace mysqldatebase.model{//<summary>////This helper class is used to get session, use session to manipulate database/        </summary> class Nhibernatehelper {//Singleton mode sessionfactory can get session, use session can go to manipulate database.        private static isessionfactory sessionfactory = null; private static string datebase = "Game"; Database name private static string dateusername = "root"; Database user name private static string Datepassword = "root"; Database Password private static isessionfactory Sessionfactory {get {if (Sessi                Onfactory = = null) initsessionfanctory ();            return sessionfactory;            }}/Initialize sessionfactory private static void Initsessionfanctory () {/* exception occurred:            Unhandled exception of type "FluentNHibernate.Cfg.FluentConfigurationException" in Workaround in FluentNHibernate.dll: Download Mysql-connector-net-6.9.9.msi for installation, use MySql.Data.dll connection http://dev.my sql.com/downloads/connector/net/*/sessionfactory = FLUENTNHIBERNATE.CFG.FLUENTLY.C Onfigure (). Database (FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString (db = db). Server ("localhost"). Database (datebase). Username (Dateusername). Password (Datepassword)). Mappings (x = x.fluentmappings.addfromassemblyof<nhibernatehelper> ()).        Buildsessionfactory (); }//used to get session public static ISession Opensession () {return sessionfactory.opensession ()        ; }    }}

  

2. Create the Nhibernatehelper help class to generate the Sessionfactory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.