September 03, 2010
Best sellers

Classifieds With Friendly URL DNN 4.x.x and 5.x.x
List Price: $45.00
Price: $39.00
You Save: $6.00

Events Listings with Friendly URLs DNN 4.x.x and 5.x.x
List Price: $40.00
Price: $35.00
You Save: $5.00

Quiz Module 3 Modules in one package for DNN 4.x.x and 5.x.x
List Price: $55.00
Price: $49.00
You Save: $6.00

 

Print  Minimize
Latest DnnMine News

Current Articles | Categories | Search | Syndication

LINQ and DotNetNuke - Creating a compiled module - Part I

So far all the DotNetNuke modules which I have developed used the standard SQLDataProvider for DotNetNuke. Since I have been using LINQ extensively for non DotNetNuke projects I have been meaning to use LINQ with DotNetNuke.

Heres a few steps on how to implement LINQ + DotNetNuke

Use Starter Module from BiteTheBullet.co.uk

I have the DotNetNuke Compiled C# module from BiteTheBullet.co.uk as a starting template for developing module. I like it because it allows you to create a compiled DLL which you can package and deploy. I would suggest downloading the Compiled Module project from here http://www.bitethebullet.co.uk/DNN4CSharpTemplate/tabid/79/Default.aspx 

Follow steps outlined on bitethebullet.co.uk to create and compile a module. Once you have that continue on as below...

Heres the solution view of module I created using the started module.

I named my module DNNLinqSample  

 
Navigate to the project properties and set the Application Target Framework to .Net 3.5
 
 

 
Compile again to make sure it builds.
 

Bringing in LINQ 

Add a new project to the solution and select a project type as "Class Library"

 

 
This is going to be the project that we use to connect to our Database tables using LINQ. Note that the project is created in the folder DesktopModules.
The Class Library project is created with a default class "Class1.cs" [Class1.vb if you are using VB]
Delete this class from the project.
 
 
 

 
Right click on the project DNNLinqDBConn and add file type "LINQ to SQL Classes". I have named it "LinqSampleDBML.dbml"
 
 

 
In the my DotNetNuke database I have create a table called SampleLINQ. Create any table you want for your module in your DNN database and drag and drop it onto the dbml. Heres what mine looks like. Its a very simple table with two columns for Demo purpose only.
The column SampleId is the primary key table which is an Identity column.
  
 

 
 
After adding the table to the DBML, we will now make sure that we can use the connection string from our DotNetNuke instllation on deploying this module.
 

DotNetNuke Connection String 

Add another class called DNNConnString.cs to this class library project. Add the following code to this class
 
  

 
Create a partial class with the same name as in  the LINQSampleDBML.designer.cs class i.e LINQSampleDBMLDataContext in my case. The connection string is SiteSQLServer since this is the default DNN connection string.
 
This will allow you to delete the connection string in the app.config in the class library project and allow you to use the SiteSQLServer connection string for your DotNetNuke installation.
 

Note: If you drag and drop another table onto the DBML and try to compile you may get an error like the one below:

 

Error 1 Type 'DNNLinqDBConn.LINQSampleDBMLDataContext' already defines a member called 'LINQSampleDBMLDataContext' with the same parameter types C:\Work\DNN50101\DesktopModules\DNNLinqDBConn\DNNConnString.cs 10 16 DNNLinqDBConn

 

You need to delete the contructor that take in no parameters from the LINQSampleDBML.designer.cs

 

public LINQSampleDBMLDataContext() : 

base(global::DNNLinqDBConn.Properties.Settings.Default.dnn50101ConnectionString, mappingSource)

{

OnCreated();

 

 

 

 
The next step is to build the UI. LINQ + Linq aware datacontrols make it really easy to implement.
 
Continued in Part II..... 
 

posted @ Monday, September 07, 2009 8:33 AM by host

Previous Page | Next Page

COMMENTS

Hi, dow you still have the pictures? It seems that the website that you are hosting this on is down.

Iam wondering what kind of code the dnnconnectionstring would be, and how to use it to the dbml file.

Thanx,
david

posted @ Friday, May 14, 2010 10:17 AM by David


Click here to post a comment
Print  Minimize
 

Copyright 2007 by dnnmine.com
 DotNetNuke  |  Terms Of Use  |  Privacy Statement