I currently have a .NET solution I'm developing that involves several sub-projects, including an ASP.NET MVC project. My model has been separated into a separate assembly because I need to use it from the various other projects in the solution.
My model consists of an ADO.NET Entity Framework entity model. I have decided to go with a singleton pattern for my model, with the following code (SalsaEntities being the name of my entity model):
partial class SalsaEntities
{
private static SalsaEntities _instance = new SalsaEntities();
/// <summary>
/// Singleton instance of SalsaEntities.
/// </summary>
public static SalsaEntities Instance
{
get
{
return _instance;
}
}
}
I then consume SalsaEntities.Instance from my other assemblies. This works fine in a third project I have, a Windows Service, although I had to include the connection string in that project's App.Config file.
I am getting an exception, however, when I try to use the SalsaEntities.Instance from my ASP.NET MVC project. Despite including the following in the Web.config files in both the root of the project and in the Views directory...
<connectionStrings>
<add name="SalsaEntities" connectionString="metadata=res://*/SalsaModel.csdl|res://*/SalsaModel.ssdl|res://*/SalsaModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhost;Initial Catalog=DbSalsa;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
...I still have the following exception thrown:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
The assemblies all have different namespaces, but since the Windows Service accesses it just fine, I don't think that's the problem.
Help?
Thanks, David
P.S.: One more quirk I've noticed is that when telling Visual Studio to create a new strongly-typed View, it generates a file not found error regarding the model assembly. I've seen this error discussed a few times on the web with no resolution.