DNN and LINQ - Show Module List
This short tutorial is how to use ASP .NET 3.5 features inside DotNetNuke and how it can helps you to simplify a lot of things that usually created manually. This first tutorial is about showing list of modules inside a page using LINQ. This is an update version of my last tutorial on DNNWiki.net here.
The article cover :
- How to load DNN menu (or tabs) and bind it in a bindable control
- How to use DNN ClientAPI to inject confirmation window to a button control (or whatever web control you like)
- How to load DNN modules and bind it in a bindable control
- How to delete module
- How to clear DNN site cache
But this article only cover number 1 and 3 by using LINQ.
In my last article, I used DotNetNuke API. But you can do it in many ways as follow :
- Create your own store procedure or just calling DNN existing stored procedure
- Using DotNetNuke API itself
- Alternatively, by using LINQ
I will not cover the first way since you can do it easily by analyzing table structure inside DotNetNuke or by analyzing existing DotNetNuke stored procedure.
I just want to show you the different way using LINQ.
In my last article, I used this approach when populating Tabs to a dropdownlist control :
But since i'm gonna using LINQ, i can change it like below :
The result is the same, but using different way. Yes, that's tricky just to validate using TabPath. But for simplicity, it's ok. You can play with LINQ more extensively. For doing this, you have to know the table structure for each fields that refer to a DotNetNuke functionality. For example, DotNetNuke API has a lot of function that encapsulated inside a method or function like IsSuperTab, IsAdminTab. How they are different each other ? To understand this, you have to read documentation and the source code. Actually, in LINQ there are no such things like that. The solution is you have to create your custom LINQ provider or create your Extension method.
To populate list of modules inside a page, i use this code :
By using LINQ-way, i can use this approach :
Again, this LINQ code is remove the complexities when validating some information. You can add m.Module.AllTabs == false || m.Module.IsDeleted == false in WHERE clause to make it same as code before. Here, LINQ doesn't provide encapsulate mechanism as I explain before. You have to know every fields functionality in your table. Create your own LINQ provider or create Extension method.
Oh btw, this is the .dbml file that i've been created for this tutorial (i named it DNN.dbml):
This DNN.dbml will generate DNNDataContext class that you can use it in your application. For example :
The different is, now i can play with LINQ without having to know the SQL syntax to load records (and also other LINQ features). LINQ generate T-SQL nicely and do as expected IF you create right LINQ construct. So far playing with LINQ inside DotNetNuke is really having fun and provide greater flexilibity.
Next, I will explore DotNetNuke API using LINQ.
Stay tune.