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...Getting StartedGetting StartedEntity Framework Connection String with DNNEntity Framework Connection String with DNN
Previous
 
Next
New Post
11/24/2010 5:47 PM
 
I started playing with Entity Framework and Linq within custom DNN modules a while ago, and had some trouble figuring out how to build the EF connection string using nothing more than the DNN connection string.    This is the solution that I came up with.  It does not require that you add any additional connection strings (EF specific or otherwise to the web.config file).

I was wondering what other ways people have come up with to deal with the EF connection strings with their custom DNN modules.

I have a utility class with the following method in it that creates the connection string:

Public Shared Function GenerateGITasksEntityFrameworkConnection() As EntityConnection
        ' Specify the provider name, server and database. 
        Dim providerName As String = ConfigurationManager.ConnectionStrings("SiteSqlServer").ProviderName

        ' Initialize the connection string builder for the underlying provider. 
        Dim sqlBuilder As New SqlConnectionStringBuilder()

        ' Set the properties for the data source. 
        sqlBuilder.ConnectionString = ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString

        ' Initialize the EntityConnectionStringBuilder. 
        Dim entityBuilder As New EntityConnectionStringBuilder()

        'Set the provider name. 
        entityBuilder.Provider = providerName

        ' Set the provider-specific connection string. 
        entityBuilder.ProviderConnectionString = sqlBuilder.ToString()

        ' Set the Metadata location. 
        entityBuilder.Metadata = "res://*/Data.MyModule.csdl|res://*/Data.MyModule.ssdl|res://*/Data.MyModule.msl"

        Return New EntityConnection(entityBuilder.ToString())
    End Function

Then call the static method as shown below:

MyContext = New MyModule.Common.Entities(MyModule.Common.Utility.GenerateGITasksEntityFrameworkConnection())

Again, this is my solution, but it does only work when the connection string name is SiteSqlServer and when the database server is Sql Server.    So it does have it's limitations.   What other solutions have others people come up with in regards to the EF connection string?

Chaitanya
 
New Post
10/31/2011 10:32 PM
 
Thank you for this.  This is a nice, elegant solution to this issue.  I'd really like to see an implementation of the DNN Provider pattern using EF.

Gabe
 
New Post
11/1/2011 5:56 AM
 
Chaitanya, please enter your findings as enhancement suggestion into the DNN issue tracker at support.dotnetnuke.com, thank you.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedEntity Framework Connection String with DNNEntity Framework Connection String with DNN


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