I have a connection string defined in my web.config like:
<connectionStrings>
<add name="LibraryConnectionString" connectionString="Server=.\SQLEXPRESS3;Database=Library;Integrated Security=true" />
Well...lI do not understand why when i drag-and-drop tables into a new DataClasses dbml it does not construct a default constructor specifying the connection string....
I only have constructor with params like:
public DataClassesDataContext(string connection) :
base(connection, mappingSource)
{
开发者_如何学JAVA OnCreated();
}
I do need a default constructor for LinqDataSource..
Can anyone suggest a work-around?
Thanks
- Step 1 : Remember your dbml file name and delete your dbml file.
- Step 2 : Then add a new dbml file with the same previous name to the same location (add -> add new Item -> LINQ to SQL Classes).
- Step 3 : Double click on the dbml file in the Solution Explorer.
- Step 4 : Now Drag and drop all the tables to that layout of dbml.
- Step 5 : Finally add all the associations with the tables as previously you have done.
- NO ERRORS,,,No need to make a default constructor by your own.It automatically create the constructor with out arguments if you do as i mentioned,,,and when ever you change any data it can automatically change as you need ...THANX ..PLEASE VOTE MY ANSWER
You can make a default constructor in a separate file like this:
partial class DataClassesDataContext
public DataClassesDataContext()
: this(ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString) {
}
}
Make sure not to call OnCreated
twice.
精彩评论