82
HO CHI MINH UNIVERSITY OF INDUSTRY Author: Trần Duy Thanh – Phone : 0987773061- Email: [email protected]– Blog: http://duythanhcse.wordpress.com Generator

All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Embed Size (px)

Citation preview

Page 1: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Generator

Page 2: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

http://www.codesmithtools.com/plinqo

All information's of PLINQO in this Document, I got it from:

So, you could visit the link above to research

Page 3: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Introduce CodeSmith generator - PLINQO1

What is PLINQO for NHibernate?2

Key features PLINQO for Nhibernate.3

Getting Started Steps PLINQO for Nhibernate.4

Page 4: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

PLINQO is an enhanced alternative for the most popular Object Relational Mapping frameworks. It is a set of CodeSmith Templates designed to simplify the creation and maintenance of data models, as well as provide you with an easy to use data access layer that adhears to best practices.

Introduce CodeSmith generator - PLINQO1

Page 5: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Microsoft's minimalist approach to ORMs, LINQ to SQL is the original lightweight LINQ implementation for data access.

Page 6: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Entity Framework is Microsoft's ORM of choice. It is an advanced framework that uses multiple models to allow for flexibility.

Page 7: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

NHibernate is the open source community's ORM of choice. It is a port of Hibernate for Java that has taken on a life of it's own.

Page 8: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Key Features:

Instant Data Layer Generation1.1

Safe Regeneration and Synchronization

1.2

Open Source 1.3

Page 9: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Instant Data Layer Generation1.1

PLINQO will generate all of your database mappings, business entities, and query extensions instantly. Each generated class is separated into editable and generated files, all of which are organized into an intelligible folder structure.

Page 10: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Safe Regeneration and Synchronization

1.2

Quickly and safely regenerate your data layer against your database. PLINQO intelligently seeks out and merges data changes with code changes, allowing you customize your ORM mappings and safely regenerate them!

Page 11: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Open Source 1.3All PLINQO templates and libraries are open source. This puts you in complete control of your source code, and allows you to customize your data layer to fit your needs. Interested in sharing your changes? Submit a patch and get it put into the next build of PLINQO

Page 12: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

What is PLINQO for NHibernate?2

- PLINQO NH is a Replace and Enhance alternative to NHibernate.

- PLINQO NH is available in C#, and supports SQL Server, Oracle, DB2, MySQL, and more!

Page 13: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

What is PLINQO for NHibernate?2

PLINQO is a set of CodeSmith Templates that generate ORM (Object Relational Mapping) frameworks using consistent design patterns and best practices. PLINQO Frameworks also include an advanced set of features to both simplify and optimize the task of data access.

Page 14: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

What is PLINQO for NHibernate?2

Advantaged:- simplifications- optimizations- convenience

The ultimate goal is to take the best of both worlds and put them together into a robust framework that is easy to use.

Without write CRUD (Create, Retrieve, Update, Delete) Method

Page 15: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Key features PLINQO for Nhibernate.3

PLINQO can generated your HBM files, entity classes, and all NHibernate configuration in seconds. It then allows you to safely regenerate that code at anytime, thus synchronizing your mappings with the database while still intelligently preserving custom changes.

Page 16: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Key features PLINQO for Nhibernate.3

Data Layer Generation3.1

Safe Regeneration3.2

Intuitive File Structure3.3

Query Logic3.4

Page 17: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Data Layer Generation3.1

• Generate your HBM files from your database.

• Supports Tables, Views, and Stored Procedures.

• Supports associations and composite keys.

• Generate your Entities from your HBM files.

Page 18: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Safe Regeneration3.2

• Safely regenerate your data layer against your database.

• Intelligently seeks out and merges data changes with code changes.

• Ability to filter what gets updated from the database.

Page 19: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Intuitive File Structure3.3

• Each generated class is separated into editable and generated files.

• Complex types are generated into an organized folder structure.

Page 20: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Query Logic3.4

• Generates chainable query extension methods that simplify query logic.

• Query extensions support advanced comparison and containment operators.

Page 21: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Getting Started Steps PLINQO for Nhibernate.4

How to install CodeSmith Generation4.1

Quick Start4.2

Manual Configuration4.3

Page 22: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

How to install CodeSmith Generation4.1

http://code.google.com/p/codesmith/downloads/list?can=3&q=nhibernate

Download latest:

http://docs.codesmithtools.com/display/NHibernate/Getting+Started

Getting Started:

http://docs.codesmithtools.com/display/NHibernate/Home

Documentation:

http://docs.codesmithtools.com/display/NHibernate/Downloads

Additional download and samples:

Page 23: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

How to install CodeSmith Generation4.1

These templates are dependent on the following:Development Applications:

CodeSmith Generator Professional 5.x Microsoft Visual Studio 2010

Runtime Assemblies: .NET 4.0 NHibernate 3.2.0.GA

Page 24: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

I downloaded and installed CodeSmith Generator 6.0

Page 25: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

In the Start menu & Desktop Icon

Page 26: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

In the Generator Menu or in the Add New Item dialog

Page 27: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Quick Start4.2

1.Open QuickStart.cst 2.Select a SourceDatabase. 3.Click Generate!

See details in the next slide

Page 28: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Double click on the CodeSmith Generator Explorer Icon see the Code Smith Generator Explorer dialog

Page 29: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

1.Database2.Solution3.Data Project4.Web Project5.Test Project

Database Picker here

Page 30: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

I use Petshop database to demo

The Category table will be use (3 columns)

Page 31: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Name: define nameProvider Type: SqlSchemaProviderConnection String: use to connect to SqlServer, string connect as the same in the .Net. So you could copy & paste from .Net

Click Test button to test connecting

Page 32: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

When select Datasource from Database picker, You will see the result in the left slide

You could change location

Now, click Generate button

DataContext here

Page 33: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

In the E:/example folder

In the Petshop.Data, open Petshop.Data.csproj

Page 34: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Right click on the Petshop.Data.csp and choose Generate Outputs

Page 35: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Take the tour Generate :ReferencesEntitiesMapsModelsQueriesEntityBaseDataContext

Page 36: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

References

Page 37: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Entities

Page 38: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Maps:Entities Columns in tableFunctions Store ProcedureViews View in database

Page 39: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Maps:Entities Columns in table

Page 40: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Maps:Functions Store Procedure

Page 41: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Maps:Views View in database

Page 42: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Models

Page 43: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Queries

Page 44: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

EntityBasePetshopDataContext

Page 45: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Petshop.UI

Open Web.config, you will see connectionStrings tag as below:

I add new WebForm1.aspx to test

Page 46: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Petshop.UI

Right click on Project / Add new Item/ WebForm

Page 47: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Control Name Text

ListBox listCate Display list Cate

Button btnGetListCate Get List Categories

Button btnInsert Insert

Button btnUpdate Update

Button btnDelete Delete

TextBox txtCateId Using display Cate Id

TextBox txtName Using display Cate Name

TextBox txtDescription Using display description

Page 48: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Get List Categories

Page 49: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Selected ListBox

Page 50: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Delete Category

Page 51: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Update Category

Page 52: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Insert Category???

Page 53: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Manual Configuration4.31.Add a CodeSmith Project to your CSharp Project

1. Open your project in Visual Studio. 2. Right click on your project in Solution Explorer and add a "New

Item" 3. Under "Visual Studio C# Items", and add a "CodeSmith

Project" 2.Configure your CSP for PLINQO NHibernate

1. Right click on the CSP and "Manage Outputs" 2. Add Output, select Hbms.cst, and fill in the 2 required

properties 3. Add Output, select Entities.cst, and fill in the 2 required

properties 4. Add Output, select Queries.cst, and fill in the 1 required

property 5. Right click on the CSP and "Generate Outputs"

3.Add a connection string to your App or Web config 1. Name the connection string "nhiberante" or the name of your

database

Page 54: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

1. Create Blank Solution with name: StudyCodeSmith

Page 55: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

2. Add Petshop.Data class library project into solution

Right click on Solution/ Add/ New Project/ choose Class LibraryEnter Petshop.Data into Name box then click Ok button

Page 56: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

3. Add CodeSmith Project into Petshop.Data project

Right click on Petshop.Data/ Add/ New Item

Page 57: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

3. Add CodeSmith Project into Petshop.Data project

Choose Generator Project inside CodeSmith Generator, then click Add button

Page 58: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

4. Configure your CSP for PLINQO NHibernate

Right click on Project1.csp / choose Manage Outputs

Page 59: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

C:\Users\ainuong\Documents\CodeSmith Generator\Samples\v6.0\Templates\Frameworks\PLINQO-NH\CSharp

Assume that, Template in here (you could change location when you Setup CodeSmith Generator):

Click Add Output button

3 Templates:Hbms.cstEntities.cstQueries.cst

InHere

If you don’t know templates location, Please open CodeSmith Generator Explorer, Right click on Templates / Properties to see Templates location.

Page 60: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Define Name what you want

Choose Hbms.cst template location here

Configure as the same Quick Started

Process for Hbms.cst template

Page 61: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Process for Entities.cst template

Choose Entities.cst template location here

Page 62: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Final, you got 3 outputs below:

Page 63: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Process for Queries.cst template

Choose Queries.cst template location here

Page 64: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Right click on Project1.csp/ choose Generate Ouputs

Page 65: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Results as you see…

Page 66: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

I add new Petshop.UI winform project. Also, add App.config file

Page 67: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

App.config file here

Page 68: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Copy & paste connection string or enter by hand:

Hint: In case Quick Started, CodeSmith auto gen connectionString in to App.config or Web.config, you could copy from here

Page 69: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Add Reference Petshop.Data to Petshop.UI

Right click on Petshop.UI/Add References…

Page 70: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

C:\Users\ainuong\Documents\CodeSmith Generator\Samples\v6.0\Templates\Frameworks\PLINQO-NH\Common\NHibernate\

Add Reference Nhibernate library for Petshop.UI

In this case, DLL in my computer location here:

Page 71: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Select dll and click OK to add Reference…

Page 72: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

C:\Users\ainuong\Documents\CodeSmith Generator\Samples\v6.0\Templates\Frameworks\PLINQO-NH\Common\CodeSmith.Data\

Add Reference CodeSmith library for Petshop.UI

In this case, DLL in my computer location here:

Select dll and click OK to add Reference…

Page 73: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

All References here

Page 74: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

All DLL, config file in Release

Page 75: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Choose .NET Framework 4

Page 76: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Control Name Text

ListBox listCate Display list Cate

ListBox listProduct Display list Product

Button btnGetList Get List Categories

Button btnInsert Insert

Button btnUpdate Update

Button btnDelete Delete

TextBox txtCateID Display Cate ID

TextBox txtName Display Cate Name

RichTextBox rtbDescription Display Cate description

Page 77: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

using Petshop.Data;using Petshop.Data.Entities; PetshopDataContext context;

private void btnGetList_Click(object sender, EventArgs e) { context = new PetshopDataContext(); var list = from cate in context.Category select cate; listCate.DataSource= list.ToList(); listCate.DisplayMember = "Name"; listCate.ValueMember = "CategoryId"; }

When click Get List Categories button, you will see Data display…

Page 78: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

private void listCate_SelectedIndexChanged(object sender, EventArgs e)

{ if (listCate.SelectedValue != null) {

Petshop.Data.Entities.Category c = (Petshop.Data.Entities.Category)listCate.SelectedItem;

txtCateID.Text = c.CategoryId;txtName.Text = c.Name;rtbDescription.Text = c.Description;

listProduct.Items.Clear(); foreach (var p in c.ProductList){ listProduct.Items.Add(p.ProductId +" --- "+p.Name); } }}

Get detail information for each catalog, also display list product of this

Page 79: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Click on the Cate name to show detail information and list product

Page 80: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

private void btnUpdate_Click(object sender, EventArgs e)

{ if (listCate.SelectedValue != null) { Petshop.Data.Entities.Category c = (Petshop.Data.Entities.Category)listCate.SelectedItem; c.Name = txtName.Text; c.Description = rtbDescription.Text; context.Category.InsertOnSubmit(c); context.SubmitChanges(); btnGetList.PerformClick(); }}

Update Information

Page 81: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Delete Information

private void btnDelete_Click(object sender, EventArgs e)

{ if (listCate.SelectedValue != null) { Petshop.Data.Entities.Category c = (Petshop.Data.Entities.Category)listCate.SelectedItem; context.Category.DeleteOnSubmit(c); context.SubmitChanges(); btnGetList.PerformClick(); }}

Page 82: All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research

Insert Information

???