or mapping- nhibernate presentation

25
Presentation Agenda on nhibernate: By: Shahzad Sarwar To: Development Team

Upload: shahzad

Post on 12-May-2015

2.273 views

Category:

Technology


4 download

DESCRIPTION

Agenda:OR Mapping- nhibernate To: Development Team By: Shahzad Sarwar

TRANSCRIPT

Page 1: OR Mapping- nhibernate Presentation

Presentation Agenda on nhibernate:

By: Shahzad SarwarTo: Development Team

Page 2: OR Mapping- nhibernate Presentation

Part 1: 1st Aug 2009 3:30 PMWhat is OR Mapping......................................................................................................3What is nHibernate?.......................................................................................................3XML Configuration File..................................................................................................3Persistent vs transient Objects...................................................................................4Nhibernate Basic.............................................................................................................4Code generation..............................................................................................................51. Avva Open source Solution.....................................................................................52. NConstruct Lite.........................................................................................................14CRUDE Operation Sample..........................................................................................20Nhibernate Analyiser:..................................................................................................201. SQL Server Analyiser..........................................................................................202. nhIbernate Analyiser............................................................................................23

Part 2: Later Version 2.1 new features Performance tuning Proxing Cache Design pattern for NHibernate Case Specific provider

Page 3: OR Mapping- nhibernate Presentation

What is OR Mapping.OR Mapping FrameworksOverview of LINQTypes of LINQLINQ 2 SQLLINQ 2 EntitiesSamples for LINQ

What is nHibernate?A .Net port of Hibernate of JavaCovers: Mapping and Data query formatHides SQL and ADO.NET.

XML Configuration File<?xml version='1.0' encoding='utf-8'?><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

<!-- an ISessionFactory instance -->

Page 4: OR Mapping- nhibernate Presentation

<session-factory> <!-- properties --> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string">Server=localhost;initial catalog=nhibernate;User Id=;Password=</property> <property name="show_sql">false</property> <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property> <property name="use_outer_join">true</property>

<!-- mapping files --> <mapping resource="NHibernate.Auction.Item.hbm.xml" assembly="NHibernate.Auction" /> <mapping resource="NHibernate.Auction.Bid.hbm.xml" assembly="NHibernate.Auction" /> </session-factory></hibernate-configuration>

Persistent vs transient ObjectsLevel of abstractionPage/Application level scope.Eg: Datetime dt; Session/application level vatablesDB Level Even shutdown of machineSearlization as file /DB

POCO vs POJOSamples

Nhibernate BasicMapping file - hbm.xmlEntity class

public class Category { #region Fields private int _CategoryID; private string _Description; #endregion #region Constructors /// <summary> /// Initializes a new instance of the Account class /// </summary> public Category() { } public Category(int CategoryID, string Description) {

this._CategoryID = CategoryID; this._Description = Description;

Page 5: OR Mapping- nhibernate Presentation

} #endregion

#region Properties /// <summary> /// Gets or sets theCategoryID for the current Category); /// </summary>

public virtual int CategoryID { get { return _CategoryID; } set { _CategoryID = value; } }

/// <summary> /// Gets or sets theDescription for the current Category); /// </summary>

public virtual string Description { get { return _Description; } set { _Description = value; } }

#endregion

}<?xml version="1.0" encoding="utf-8" ?><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHDEMO" namespace="Lib"><class name="Category" table="Category" dynamic-update="true" optimistic-lock="dirty" > <id name="CategoryID" column="CategoryID"> <generator class="native"/> </id>

<property name="Description" column="Description" type="String" length="250" /> </class>

</hibernate-mapping>

Show samples

Code generation1. Avva Open source SolutionGet latest copy from $\NHTool.rootSee attached Manual.

Page 6: OR Mapping- nhibernate Presentation

Introduction

Here is a tool for the use of your own applications that NHibernate. You can easily install and use this helper kit. To download, please click the link at the top of the page. If you are using NHibernate, you need to write a lot of persistent classes and XML mapping for each persistent class. Also, you need to write the NHibernate config file. At this point, using this tool, you can automatically create all these files in a few seconds.

Using

There are four tab screens on the tool.

Page 7: OR Mapping- nhibernate Presentation

1. Connection: This screen allows you to connect your database with connection parameters. It looks like the Visual Studio connection wizard. You need to set some parameters to connect to your database.

2. Tables & Columns: This screen allows you to browse a selected database's tables and select them to create files. Also, if you want, you can see a table's column information by selecting from a table from a list and clicking "Preview Columns".

Page 8: OR Mapping- nhibernate Presentation
Page 9: OR Mapping- nhibernate Presentation

3. Settings: This screen allows you to select some features, for example, copy the NHibernate DLL and use dynamic updates. Also, you have to select your project folder to configure the folders, namespaces, and assembly names.

Page 10: OR Mapping- nhibernate Presentation

4. Generate: At the end of this, we can start the generate process. Just click Run and wait a few seconds. You can view all the process details in this section.

Page 11: OR Mapping- nhibernate Presentation

After you've successfully completed the generating process, you can see the generated files in the project folder. If you selected "Copy NHibernate DLL to project" and other DLLs, the generator will copy it and create an NHibernate config file in your project's "bin" folder.

Page 12: OR Mapping- nhibernate Presentation

Also, the generator creates a folder named App_Code in your project folder to put persistent classes and mapping files in. It directly creates persistent classes to App_Code, and mapping files creates them in the NHMappings folder, as follows:

Let's check it out how it's looking.

Persistent class

Page 13: OR Mapping- nhibernate Presentation

Mapping the XML file

Page 14: OR Mapping- nhibernate Presentation

2. NConstruct LiteNeat Code, but not customizable as it is commercial product

Page 15: OR Mapping- nhibernate Presentation
Page 16: OR Mapping- nhibernate Presentation
Page 17: OR Mapping- nhibernate Presentation
Page 18: OR Mapping- nhibernate Presentation
Page 19: OR Mapping- nhibernate Presentation
Page 20: OR Mapping- nhibernate Presentation

CRUDE Operation Sample

See Sample demo for CRUDE operations.

dynamic-updatedynamic-insertselect-before-updateone-to-oneone-to-manymany-to-onebagfetch = join-select for categoryHQLcascade

Nhibernate Analyiser:1. SQL Server Analyiser

Page 21: OR Mapping- nhibernate Presentation
Page 22: OR Mapping- nhibernate Presentation
Page 23: OR Mapping- nhibernate Presentation

2. nhIbernate Analyiser

Page 24: OR Mapping- nhibernate Presentation

3.