What is OR Mapping



Presentation Agenda on nhibernate:

By: Shahzad Sarwar

To: Development Team

Part 1: 1st Aug 2009 3:30 PM

What is OR Mapping. 3

What is nHibernate? 3

XML Configuration File 3

Persistent vs transient Objects 4

Nhibernate Basic 4

Code generation 5

1. Avva Open source Solution 5

2. NConstruct Lite 14

CRUDE Operation Sample 20

Nhibernate Analyiser: 20

1. SQL Server Analyiser 20

2. nhIbernate Analyiser 23

Part 2: Later

• Version 2.1 new features

• Performance tuning

• Proxing

• Cache

• Design pattern for NHibernate

• Case Specific provider

What is OR Mapping.

OR Mapping Frameworks

Overview of LINQ

Types of LINQ

LINQ 2 SQL

LINQ 2 Entities

Samples for LINQ

What is nHibernate?

A .Net port of Hibernate of Java

Covers: Mapping and Data query format

Hides SQL and .

[pic]

XML Configuration File

NHibernate.Connection.DriverConnectionProvider

NHibernate.Driver.SqlClientDriver

Server=localhost;initial catalog=nhibernate;User Id=;Password=

false

NHibernate.Dialect.MsSql2000Dialect

true

Persistent vs transient Objects

Level of abstraction

Page/Application level scope.

Eg:

Datetime dt;

Session/application level vatables

DB Level

Even shutdown of machine

Searlization as file /DB

POCO vs POJO

Samples

Nhibernate Basic

Mapping file - hbm.xml

Entity class

public class Category

{

#region Fields

private int _CategoryID;

private string _Description;

#endregion

#region Constructors

///

/// Initializes a new instance of the Account class

///

public Category()

{

}

public Category(int CategoryID, string Description)

{

this._CategoryID = CategoryID;

this._Description = Description;

}

#endregion

#region Properties

///

/// Gets or sets theCategoryID for the current Category);

///

public virtual int CategoryID

{

get { return _CategoryID; }

set { _CategoryID = value; }

}

///

/// Gets or sets theDescription for the current Category);

///

public virtual string Description

{

get { return _Description; }

set { _Description = value; }

}

#endregion

}

Show samples

Code generation

1. Avva Open source Solution

Get latest copy from

$\NHTool.root

See attached Manual.

[pic]

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.

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.

[pic]

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".

[pic]

[pic]

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.

[pic]

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.

[pic]

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.

[pic]

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:

[pic]

[pic]

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

Persistent class

[pic]

Mapping the XML file

[pic]

2. NConstruct Lite

Neat Code, but not customizable as it is commercial product

[pic]

[pic]

[pic]

[pic]

[pic]

[pic]

CRUDE Operation Sample

See Sample demo for CRUDE operations.

dynamic-update

dynamic-insert

select-before-update

one-to-one

one-to-many

many-to-one

bag

fetch = join-select for category

HQL

cascade

Nhibernate Analyiser:

1. SQL Server Analyiser

[pic]

[pic]

[pic]

2. nhIbernate Analyiser

3. [pic]

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download