Download presentation
Presentation is loading. Please wait.
Published byHolly Turner Modified over 9 years ago
2
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
3
Introduce CodeSmith generator - PLINQO 1 What is PLINQO for NHibernate? 2 Key features PLINQO for Nhibernate. 3 Getting Started Steps PLINQO for Nhibernate. 4
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 - PLINQO 1
5
Microsoft's minimalist approach to ORMs, LINQ to SQL is the original lightweight LINQ implementation for data access.
6
Entity Framework is Microsoft's ORM of choice. It is an advanced framework that uses multiple models to allow for flexibility.
7
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.
8
Key Features: Instant Data Layer Generation 1.1 Safe Regeneration and Synchronization 1.2 Open Source 1.3
9
Instant Data Layer Generation 1.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.
10
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!
11
Open Source 1.3 All 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
12
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!
13
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.
14
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
15
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.
16
Key features PLINQO for Nhibernate. 3 Data Layer Generation 3.1 Safe Regeneration 3.2 Intuitive File Structure 3.3 Query Logic 3.4
17
Data Layer Generation 3.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.
18
Safe Regeneration 3.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.
19
Intuitive File Structure 3.3 Each generated class is separated into editable and generated files. Complex types are generated into an organized folder structure.
20
Query Logic 3.4 Generates chainable query extension methods that simplify query logic. Query extensions support advanced comparison and containment operators.
21
Getting Started Steps PLINQO for Nhibernate. 4 How to install CodeSmith Generation 4.1 Quick Start 4.2 Manual Configuration 4.3
22
How to install CodeSmith Generation 4.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:
23
How to install CodeSmith Generation 4.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
24
I downloaded and installed CodeSmith Generator 6.0
25
In the Start menu & Desktop Icon
26
In the Generator Menu or in the Add New Item dialog
27
Quick Start 4.2 1.Open QuickStart.cst 2.Select a SourceDatabase. 3.Click Generate! See details in the next slide
28
Double click on the CodeSmith Generator Explorer Icon see the Code Smith Generator Explorer dialog
29
1.Database 2.Solution 3.Data Project 4.Web Project 5.Test Project Database Picker here
30
I use Petshop database to demo The Category table will be use (3 columns)
31
Name: define name Provider Type: SqlSchemaProvider Connection 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
32
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
33
In the E:/example folder In the Petshop.Data, open Petshop.Data.csproj
34
Right click on the Petshop.Data.csp and choose Generate Outputs
35
Take the tour Generate : References Entities Maps Models Queries EntityBase DataContext
36
References
37
Entities
38
Maps: Entities Columns in table Functions Store Procedure Views View in database Maps: Entities Columns in table Functions Store Procedure Views View in database
39
Maps: Entities Columns in table Maps: Entities Columns in table
40
Maps: Functions Store Procedure Maps: Functions Store Procedure
41
Maps: Views View in database Maps: Views View in database
42
Models
43
Queries
44
EntityBase PetshopDataContext EntityBase PetshopDataContext
45
Petshop.UI Open Web.config, you will see connectionStrings tag as below: I add new WebForm1.aspx to test
46
Petshop.UI Right click on Project / Add new Item/ WebForm
47
ControlNameText ListBoxlistCateDisplay list Cate ButtonbtnGetListCateGet List Categories ButtonbtnInsertInsert ButtonbtnUpdateUpdate ButtonbtnDeleteDelete TextBoxtxtCateIdUsing display Cate Id TextBoxtxtNameUsing display Cate Name TextBoxtxtDescriptionUsing display description
48
Get List Categories
49
Selected ListBox
50
Delete Category
51
Update Category
52
Insert Category ???
53
Manual Configuration 4.3 1.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
54
1. Create Blank Solution with name: StudyCodeSmith
55
2. Add Petshop.Data class library project into solution Right click on Solution/ Add/ New Project/ choose Class Library Enter Petshop.Data into Name box then click Ok button
56
3. Add CodeSmith Project into Petshop.Data project Right click on Petshop.Data/ Add/ New Item
57
3. Add CodeSmith Project into Petshop.Data project Choose Generator Project inside CodeSmith Generator, then click Add button
58
4. Configure your CSP for PLINQO NHibernate Right click on Project1.csp / choose Manage Outputs
59
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.cst Entities.cst Queries.cst In Here If you don’t know templates location, Please open CodeSmith Generator Explorer, Right click on Templates / Properties to see Templates location.
60
Define Name what you want Choose Hbms.cst template location here Configure as the same Quick Started Process for Hbms.cst template
61
Process for Entities.cst template Choose Entities.cst template location here
62
Final, you got 3 outputs below:
63
Process for Queries.cst template Choose Queries.cst template location here
64
Right click on Project1.csp/ choose Generate Ouputs
65
Results as you see…
66
I add new Petshop.UI winform project. Also, add App.config file
67
App.config file here
68
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
69
Add Reference Petshop.Data to Petshop.UI Right click on Petshop.UI/ Add References…
70
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:
71
Select dll and click OK to add Reference…
72
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…
73
All References here
74
All DLL, config file in Release
75
Choose.NET Framework 4
76
ControlNameText ListBoxlistCateDisplay list Cate ListBoxlistProductDisplay list Product ButtonbtnGetListGet List Categories ButtonbtnInsertInsert ButtonbtnUpdateUpdate ButtonbtnDeleteDelete TextBoxtxtCateIDDisplay Cate ID TextBoxtxtNameDisplay Cate Name RichTextBoxrtbDescriptionDisplay Cate description
77
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…
78
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
79
Click on the Cate name to show detail information and list product
80
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
81
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(); }
82
Insert Information ???
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.