Note: The examples are for VB.NET.
I have a separate assembly that hosts the layer containing my LINQ to SQL model. If you're going to use the L2S designer, you need to let L2S store the connectionstring in the settings.settings file, as shown here.

This is great, until you move your website to staging/production. You need to be able to change this connectionstring by way of a web.config setting. This method assumes that your L2Q data context has the following settings:
Connection: ExampleConnectionString (MySettings)
Connection String: xxx
Application Settings: True
Settings Property Name: ExampleConnectionString
It turns out that it’s really simple. Just add a connectionstring entry to override the one in the assembly containing the L2S connectionstring. Here’s mine for the example above:
<connectionStrings>
<add name="App.My.MySettings.ExampleConnectionString"
connectionString="server=svrprod; uid=secureuser;password=xxx; initial catalog=db"
providerName="System.Data.SqlClient" />
</connectionStrings>
The key is the name. You have to prefix your connection string’s name with “RootNamespaceForYourAssembly.My.MySettings.”. That’s it. Your web.config settings will now override the assembly’s settings when you view the website, and yet the designer will continue to use the settings in the assembly!
John
ps. I do recommend you verify your changes before moving this to production to make sure your web.config connectionstring is being used. To do this, simply make your production web.config connectionstring point to an invalid server and make sure you get the error on your website. That way you’ll know for sure that it’s reading it correctly.
bdcfc2ee-d598-48ce-b504-d6b89a70fee0|0|.0
Tags: vb.net |
Posted by
Admin on
5/17/2008 4:08 AM |
Comments (0)
[UPDATE]
Solved... well, not solved, but explained. The VB team has valid reasons for not supporting object as an extension parameter type. The key to take away from the linked article is that, when you specify object, it means "take anything *other* than an object".
http://blogs.msdn.com/vbteam/archive/2007/01/24/extension-methods-and-late-binding-extension-methods-part-4.aspx
[/UPDATE]
I'm trying to create an extension method that takes any object. It's irrelevant what I want it to do. The problem is that I can't get Extension Methods that take objects to work correctly in VB.NET. I don't have any problems with doing this in C#.
I created a simple console app to show my issues. I have two extension methods. One takes an object, and one takes a string. The code, along with the issues I'm having, are shown in detail below.
With a string, both methods show up in Intellisense.

With an object, the object extension method doesn't appear

However, it will compile

When running, however, an error occurs on the o.TestObjExt() line

Oh, but wait, if I run the same line from the Immediate window, it works!

So, I don't know what's happening. It seems to be a compiler issue, but I can't figure it out. Does anybody have any ideas what might be going on?
019d0e86-62b4-4fb3-ba56-54dce8a262e2|0|.0