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.....