《NHibernate in Action》讀書筆記【二】

Basic Configuration

1.Creating a SessionFactory :

    

 

 

It's event possible to embed XML mapping files inside .NET assemblies. You have to tell the compiler that each of these files is an embedded resource.

 

The AddClass() method assumes that the name of the mapping file ends with the .hbm.xml extension and is embedded in the same assembly as the mapped class file.

 

 If you want to add all mapped classes (with .NET attributes) in an assembly, you can use an overload of the method HbmSerializer.Serialize() ; or, if you want to add all mapping files embedded in an assembly, you can use the method AddAssembly ():
ISessionFactory sessionFactory = new Configuration()
   .Configure()
   .AddInputStream( // .NET Attributes
       HbmSerializer.Default.Serialize(typeof(Model.Item).Assembly) )
   .AddAssembly( typeof(Model.Item).Assembly ) // XML
   .BuildSessionFactory();

 

 

2.Configuring the ADO.NET database access

    

connection .provider :specifies the name of the .NET class implementing the IConnectionProvider interface.

dialect :specifies the name of the .NET class implementing the database Dialect .

connection.driver_class : specifies the name of the .NET class implementing the ADO.NET Driver.

connection.connection_string : specifies a standard ADO.NET connection string , used to create a database connection.

 

Setting the property show_sql to the value true enables logging of all generated SQL to the console.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章