NHIBERNATE Source code shallow reading 1
I have learned Hibernate, the impression is very deep, it is a very good O / R mapping fw. At http://nhibernate.sourceForge.net/, there is a .NET version from Java. NHIBERNATE (hereinafter referred to as NH), But it is still in the Prealpha Build 2 stage. For interest and learning .Net's goals, it took a small part of the code for two days: One of the source code notes is not rich, and the second is not very useful for Hibernate / NHibernate. Familiar, three have some knowledge points are not familiar. Preparations are as follows: 1. NHibernate Prealpha Build 22. NUnit3. NHibernate profiles Monitoring.dll.config as follows:
Xml version = "1.0" encoding = "utf-8"?>
It can be seen that the above is a standard config file, which is generally read by the System.Configuration.configurationSettings.getconfig method. The blue part is a place that is really configuring NH. In the example, I configure it using SQL Server, those Key / Value The meaning is very well understood. It is worth noting that the configuration file is important, usually for an EXE ASSEMBLY, is assemblyname.config, but for DLL assembly, the corresponding configuration file is AssemblyName.dll.config, for example: Myassy.exe -> myassy.configmyassy.dll -> myassy.dll.config I intend to last in my Monitoring.dll, one for monitoring performance stuff to use NH to persist data. This class library contains a Testcase, from NUnit to call 4. Objects to be held, ie Business Object (bo) Using
System;
Namespace
Argus.monitoring
{
Public Class Monitor
{
// DBID & DBID is the primary key that NH must require
Private int dbid;
Public int dbid {set {dbid = value;} get {return dbid;}}
Public String MonitorType {get {return "Dummy Monitor";}}
Public Double Value {Get {Return 12.34;}
Public string category {get {return "this is category";}}
Public string name {get {return "this is name";}}
Public string instance {get {return "this is instance";}}
Public String Computer {get {return "this is computer";}}
}
}
This is an extremely simplified class, omitting Member Method, or even Property SET method, because I am going to try the INSERT function first, then try the load function 5. Write a BO corresponding to the simplest mapping file
XML Version = "1.0" encoding = "UTF-8"?>
Using system;
Using nunit.framework;
Using NHibernate;
Using argus.monitoring;
Namespace Test.monitoring
{
[TestFixTure]
Public Class MonitoringTestSt
{
[Test] public void nhibernateTest ()
{
Argus.monitoring.monitor m = new argus.monitoring.monitor ();
NHIBERNATE.CFG.CONFIGURATION CFG = New nhibernate.cfg.configuration ();
Cfg.addxmlfile ("argus.monitoring.monitor.hbm.xml");
ISESSION session = cfg.buildsessionFactory () .openSession ();
Session.save (m);
session.close ();
}
}
}
(Hey, movie Down just finished, take a break, tomorrow will take every step of Test Case, what happened in NH)