I ran into a really annoying problem with my Linq to SQL project. When I add everything as part of a web project, everything goes as expected, and I can say that it uses my existing connection string stored in the web.config file, and the Linq code is pulled directly from the ConfigurationManager.
It all gets ugly when I switch the code to my own project. Ive created the app.config file, placed the connection string there, as it was in web.config, but when I try to add another table in the IDE, it forces me to either hardcode the connection string, or creates a settings file and puts it in which then a new entry is added to the app.config file with a new name.
Is there a way to save my Linq code in my own project, but still get back to my configuration file without continuously hard-coding the IDE string or creating the settings file? Im converts part of my DAL to use Linq to SQL, so Id likes to use the existing connection string that our old code uses, and also keep the value in a common place and one place instead of several points.
Manually changing the mode to WebSettings instead of AppSettings works until I try to add a new table and then return to hard-coding the value or re-creating the settings file. I also tried switching the project type to a web project, and then rename your app.config to web.config, and then everything works as Id, like it. I'm just not sure if there are any obstacles to keeping this as a web project, as it is truly not alone. The project only contains Linq to SQL code and an implementation of my repository classes.
My project layout is as follows
Website
-connectionString.config
-web.config (refers to connectionString.config)
Middle tier
-Business Logic
-Repository Interfaces
-etc.
DAL
-Linq to SQL code
-Existing SPROC code
-connectionString.config (linked from the web poject)
-app.config (refers to connectionString.config)
,
-
public DB() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString, mappingSource)
{
OnCreated();
}
Non Web Project
public DB() :
base(global::SampleProject.Data.Properties.Settings.Default.SiteSqlServer, mappingSource)
{
OnCreated();
}
, , , DBML -.