Foundations of Programming - Karl Seguin
Foundations of Programming - Karl Seguin
Foundations of Programming - Karl Seguin
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 6 - Object Relational Mappers<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
NHibernate.Dialect.MsSql2005Dialect<br />
<br />
<br />
NHibernate.Connection.DriverConnectionProvider<br />
<br />
<br />
Server=SERVER;Initial Catalog=DB;User Id=USER;Password=PASSWORD;<br />
<br />
<br />
<br />
<br />
<br />
Of the four values, dialect is the most interesting. This tells NHibernate what specific language our<br />
database speaks. If, in our code, we ask NHibernate to return a paged result <strong>of</strong> Cars and our dialect is<br />
set to SQL Server 2005, NHibernate will issue an SQL SELECT utilizing the ROW_NUMBER() ranking<br />
function. However, if the dialect is set to MySQL, NHibernate will issue a SELECT with a LIMIT. In most<br />
cases, you’ll set this once and forget about it, but it does provide some insight into the capabilities<br />
provide by a layer that generates all <strong>of</strong> your data access code.<br />
In our configuration, we also told NHibernate that our mapping files were located in the<br />
CodeBetter.<strong>Foundations</strong> assembly. Mapping files are embedded XML files which tell NHibernate<br />
how each class is persisted. With this information, NHibernate is capable <strong>of</strong> returning a Car object when<br />
you ask for one, as well as saving it. The general convention is to have a mapping file per domain object,<br />
and for them to be placed inside a Mappings folder. The mapping file for our Model object, named<br />
Model.hbm.xml, looks like:<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<strong>Foundations</strong> <strong>of</strong> <strong>Programming</strong> Copyright © <strong>Karl</strong> <strong>Seguin</strong> www.codebetter.com<br />
47