Upload
holly-turner
View
216
Download
1
Embed Size (px)
Citation preview
Generator
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
Introduce CodeSmith generator - PLINQO1
What is PLINQO for NHibernate?2
Key features PLINQO for Nhibernate.3
Getting Started Steps PLINQO for Nhibernate.4
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
Microsoft's minimalist approach to ORMs, LINQ to SQL is the original lightweight LINQ implementation for data access.
Entity Framework is Microsoft's ORM of choice. It is an advanced framework that uses multiple models to allow for flexibility.
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.
Key Features:
Instant Data Layer Generation1.1
Safe Regeneration and Synchronization
1.2
Open Source 1.3
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.
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!
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
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!
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.
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
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.
Key features PLINQO for Nhibernate.3
Data Layer Generation3.1
Safe Regeneration3.2
Intuitive File Structure3.3
Query Logic3.4
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.
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.
Intuitive File Structure3.3
• Each generated class is separated into editable and generated files.
• Complex types are generated into an organized folder structure.
Query Logic3.4
• Generates chainable query extension methods that simplify query logic.
• Query extensions support advanced comparison and containment operators.
Getting Started Steps PLINQO for Nhibernate.4
How to install CodeSmith Generation4.1
Quick Start4.2
Manual Configuration4.3
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:
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
I downloaded and installed CodeSmith Generator 6.0
In the Start menu & Desktop Icon
In the Generator Menu or in the Add New Item dialog
Quick Start4.2
1.Open QuickStart.cst 2.Select a SourceDatabase. 3.Click Generate!
See details in the next slide
Double click on the CodeSmith Generator Explorer Icon see the Code Smith Generator Explorer dialog
1.Database2.Solution3.Data Project4.Web Project5.Test Project
Database Picker here
I use Petshop database to demo
The Category table will be use (3 columns)
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
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
In the E:/example folder
In the Petshop.Data, open Petshop.Data.csproj
Right click on the Petshop.Data.csp and choose Generate Outputs
Take the tour Generate :ReferencesEntitiesMapsModelsQueriesEntityBaseDataContext
References
Entities
Maps:Entities Columns in tableFunctions Store ProcedureViews View in database
Maps:Entities Columns in table
Maps:Functions Store Procedure
Maps:Views View in database
Models
Queries
EntityBasePetshopDataContext
Petshop.UI
Open Web.config, you will see connectionStrings tag as below:
I add new WebForm1.aspx to test
Petshop.UI
Right click on Project / Add new Item/ WebForm
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
Get List Categories
Selected ListBox
Delete Category
Update Category
Insert Category???
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
1. Create Blank Solution with name: StudyCodeSmith
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
3. Add CodeSmith Project into Petshop.Data project
Right click on Petshop.Data/ Add/ New Item
3. Add CodeSmith Project into Petshop.Data project
Choose Generator Project inside CodeSmith Generator, then click Add button
4. Configure your CSP for PLINQO NHibernate
Right click on Project1.csp / choose Manage Outputs
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.
Define Name what you want
Choose Hbms.cst template location here
Configure as the same Quick Started
Process for Hbms.cst template
Process for Entities.cst template
Choose Entities.cst template location here
Final, you got 3 outputs below:
Process for Queries.cst template
Choose Queries.cst template location here
Right click on Project1.csp/ choose Generate Ouputs
Results as you see…
I add new Petshop.UI winform project. Also, add App.config file
App.config file here
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
Add Reference Petshop.Data to Petshop.UI
Right click on Petshop.UI/Add References…
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:
Select dll and click OK to add Reference…
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…
All References here
All DLL, config file in Release
Choose .NET Framework 4
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
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…
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
Click on the Cate name to show detail information and list product
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
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(); }}
Insert Information
???