Saturday, July 10, 2010

 

PLINQO or LINQ to SQL “Supercharged”: Getting Started

plinqologo

The goal of this post is to introduce you to PLINQO or Professional LINQ to Objects for CodeSmith Studio Professional to generate LINQ Entities and Query extensions.

By the end of this post you should know how to get a working Visual Studio project containing a single DBML file, Entity classes for your database tables & helpful Query Extensions generated using CodeSmith Studio and PLINQO.

PLINQO is developed by CodeSmith Tools, to follow the steps you need to have CS Studio installed, download the free trial

Let’s get started..

When we fire up CodeSmith Studio we get the Template Explorer window,expand Framework and see PLINQO installed out of the box.

codesmithtools


I have expanded the CSharp folder and notice that it contains a bunch of .cst template files,PLINQO uses them to generate our objects.

Right-click on QuickStart.cst and clicking Execute brings up this dialog with bunch of properties.

qsdialog

We look at them in just a moment, first click the … button on SourceDatabase property, for the demo I am using a Northwind database, so let’s select it.

adddbconnection

We can see that rest of the properties fill automagically,now lets take a look at each of them.

nwfilled

After the source database info, PLINQO needs to know the target language to generate the entities,location where the files will be generated and so on.

Now lets talk about the not so obvious ones.

The Data Project group tells the namespace for the data project,do we need to copy the template files to the target folder and type of queries it should generate,this has 2 options QueryExtensions and ManagerClasses, we will look them in a future post.

The Interface Project needs to know whether or not generate a Data web service file, type of project (Web application or Website) and the project name.

The Test project properties tell whether or not include a Test project in the solution and the name of the test project.

Let’s leave the default selected,specify the target Location and hit Generate,

This launches Visual Studio with a solution that contains our 3 projects.


gensolexp

To generate Entities and Queries we need to do one last step before we’re on our way.

Before we do that let’s go behind the scenes to see how PLINQO will generate the classes for us,so

Right click on Northwind.Data.csp file and select Manage Outputs.

manageop

This will bring up the following dialog, PLINQO uses the information in these outputs to generate the templates.

manageopdialog

For instance double-click on DBML will bring up a dialog where one of the things I can do is change the Ignore Pattern to exclude tables with a matching name that I don’t want or change the name of the base class for all my entities.

In Entities I can change the default location of the Entities output directory for instance, similarly in Queries I can change the default name of the Datacontext object that PLINQO generates.

Let’s leave them unchanged, Cancel the dialog and go back to the Solution Explorer.

Right-click the Northwind.Data.csp file again and this time select Generate Outputs.


genop

PLINQO will then build the solution,generate Entities and Queries required to query the database.

The final output looks like.

output

Let’s open the generated Northwind.dbml.

dbml

Perfect, now let’s go to Northwind.UI project and fire up Default.aspx in the browser.

dyndatasite

Nice so we got a fully working ASP.NET Dynamic Data web application project generated using PLINQO from a Northwind database.

In a future post we’ll see how PLINQO simplifies querying data with the help of some useful extension methods and few other tricks.

Labels: , , , ,


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?