Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Using Linq To SQL in WAP moduleUsing Linq To SQL in WAP module
Previous
 
Next
New Post
9/24/2008 11:56 AM
 

Hi Michael

I am doing the same and have conquered the first hurdle, I shall explain in a moment. However (as usual) whilst it works and applies updates, it causes an ObjectDisposedException sometime after the updates have been applied. This is caused by a <table> getter access to the DataContext after it has been disposed but there is no stack trace to go on. I have a feeling it is caused by Reflection somewhere in the DNN framework. Anyway, back to how to do it - or at least one way to do it...

Firstly I have created a base control used by each of my DNN controls. On this I have a property called Dcx of type HelpDeskDataContext (my dbml)

Private _dcx As HelpDeskDataContext
Protected ReadOnly Property Dcx() As HelpDeskDataContext
 Get
     If _dcx Is Nothing Then
        _dcx = GetDataContext()
     End If
     Return _dcx
 End Get
End Property

and a Private function as follows:-

Private Function GetDataContext() As HelpDeskDataContext
Dim dcx As HelpDeskDataContext = New HelpDeskDataContext(System.Configuration.ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
Return dcx
End Function

So at runtime, the DataContext is constructed using a secondary constructor where I can force the issue regarding the connectionstring.

On a typical control, you can place a LinqDataSourceControl (DsComments) but do not set its ContextTypeName whilst setting properties such as EnableUpdate etc. Instead, subscribe to the ContextCreating event as follows:-

Protected Sub DsComments_ContextCreating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceContextEventArgs) Handles DsComments.ContextCreating

      e.ObjectInstance = Dcx
      With DsComments
            .TableName = "hdd_Comments"
            .ContextTypeName = "Aureole.Modules.HelpDesk.HelpDeskDataContext"
            .Where = "Issue_Id == @Issue_Id"
            .WhereParameters.Add(New Parameter("Issue_Id", DbType.String))
           .OrderBy = "CreatedDate desc"
End With
End Sub

You can then easily tie up your visual controls and data binding. If using a formView, I do this on the formView.ItemCreated event since by that time, the DataSource will be fully operational and the visual controls will be accessible in the relevant formView template.

By putting the DataContext into the ancestor control it is easily available to each control in my application. I also have properties in the base control to provide lists for lookups (comboboxes) so they are easily available whenever needed. For example:-

Private _products As List(Of hdd_Product)
Protected ReadOnly Property Products() As List(Of hdd_Product)
Get
If _products Is Nothing Then
_products = (From prods In Dcx.hdd_Products).ToList
End If
            Return _products
End Get
End Property

Anyway, I am no expert and am groping my way through with both DNN and ASP.Net but discovered your post whilst seeking an answer to my own problem.

So, if it is of use then great, if anyone has ideas regarding the ObjectDisposedException then I would be keen to hear about them. In the meanwhile if I discover the root (and solution) to the problem I shall post it back here.

John

 
New Post
9/25/2008 8:46 AM
 

Well, I said I was no expert and I was right!

The solution is much simpler. First (I believe) you must build your WAP module for the DataContext to become available on the dropdown when configuring the LinqDataSource control. Certainly mine appears now but did not originally.

So now you can use the designer to link up your formviews etc.

Next, subscribe to the ContextCreating as shown above. All you need is the first line of code (however see more below).

That's it!

Now about the ObjectDisposedException. That I believe was down to the way I had implemented a "common" DataContext object in my ancestor. It is not properly managed. So I have scrapped the base control, moved the functionality into a Module and ensured that all of my references to the DataContext object are immediately disposed. Thus the line in ContextCreating becomes:-

e.ObjectInstance = Helper.GetDataContext()

John

 
New Post
9/26/2008 7:56 PM
 

Thanks for your reply John. 

Also, thanks to Hooligannes for the tip about overriding the project root.  A bit of Googling on that subject led me to this blog post by Charles Nurse: http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryID/1650/Default.aspx.  Thanks Charles! Setting up my WAP module project this way allows using F5 and Shift + F5 just the way I've done with the WSP model--I can start at the page where my module is installed and set breakpoints in my module's code without the additional step of attaching to the ASP.NET worker process.

I still don't have the "SiteSqlServer" option in the drop down for the data context's connection string.  But that's not really a problem since I am instantiating my data contexts in code and I just pass in the connection string via DNN's Config.GetConnectionString("SiteSqlServer") method.

BTW, I'm not trying to bind controls directly to the data context.  I'm just using linq to sql in my "repository" classes (data access layer) but the controller class (I'm using the model-view-presenter pattern because I want to be able to unit test my code outside of a web request) calls the methods on the repository (e.g., GetItemById(134);) and gets back an ItemInfo object or an IEnumerable<ItemInfo> that is passed to the view (.ascx file and associated codebehind).

 
New Post
10/9/2009 12:17 AM
 

Nestor is right. You do not want a web.config in your WAP. You just want to use the settings from DotNetNuke's web.config.

To get SiteSqlServer to show up in the Connection dropdown of the DataContext properties, you need to configure the project properties of your WAP:

1. On the Web tab, set the Project Url to point to your WAP's folder [http://localhost/DotNetNuke_05/DesktopModules/MyShoppingList] .

2. Set the Override Application root URL to point to your DotNetNuke installation [http://localhost/DotNetNuke_05].

This will cause the SiteSqlServer option to appear.

The Guern

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...Using Linq To SQL in WAP moduleUsing Linq To SQL in WAP module


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out