Bài giảng Công nghệ lập trình tiên tiến - PLINQO

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.

 

pptx85 trang | Chuyên mục: Lập Trình Trực Quan | Chia sẻ: dkS00TYs | Lượt xem: 4940 | Lượt tải: 4download
Tóm tắt nội dung Bài giảng Công nghệ lập trình tiên tiến - PLINQO, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
es with code changes, allowing you customize your ORM mappings and safely regenerate them! 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 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 Generation 3.1 Safe Regeneration 3.2 Intuitive File Structure 3.3 Query Logic 3.4 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. 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. Intuitive File Structure 3.3 Each generated class is separated into editable and generated files. Complex types are generated into an organized folder structure. Query Logic 3.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 Generation 4.1 Quick Start 4.2 Manual Configuration 4.3 How to install CodeSmith Generation 4.1  Download latest:  Getting Started:  Documentation:  Additional download and samples: 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 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 Start 4.2 Open QuickStart.cst Select a SourceDatabase. Click Generate! See details in the next slide Double click on the CodeSmith Generator Explorer Icon  see the Code Smith Generator Explorer dialog Database Solution Data Project Web Project Test Project Database Picker here I use Petshop database to demo The Category table will be use (3 columns) 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 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 : References Entities Maps Models Queries EntityBase DataContext References Entities Maps: 	Entities Columns in table 	Functions  Store Procedure 	Views  View in database Maps: 	Entities Columns in table	 Maps: 	Functions  Store Procedure	 Maps: 	Views  View in database Models Queries EntityBase PetshopDataContext 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 Configuration 4.3 Add a CodeSmith Project to your CSharp Project Open your project in Visual Studio. Right click on your project in Solution Explorer and add a "New Item" Under "Visual Studio C# Items", and add a "CodeSmith Project" Configure your CSP for PLINQO NHibernate Right click on the CSP and "Manage Outputs" Add Output, select Hbms.cst, and fill in the 2 required properties Add Output, select Entities.cst, and fill in the 2 required properties Add Output, select Queries.cst, and fill in the 1 required property Right click on the CSP and "Generate Outputs" Add a connection string to your App or Web config 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 Library Enter 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.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. 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 ??? Template Syntax 5 Basic Template Syntax Advanced Template Syntax 84 Basic Template Syntax The CodeTemplate Directive Including Comments Declaring and Using Properties Escaping ASP.NET Tags The CodeSmith Objects 85 Advanced Template Syntax Code Behind Model Referencing Assemblies Importing Namespaces Including External Files Sharing Common Code Debugging Templates Using Sub-Templates Outputting Multiple Files END 

File đính kèm:

  • pptx3-Week5-6_PLINQO-HN_CodeSmithGenerator.pptx.pptx
Tài liệu liên quan