Tag Archives: SQL metal

Silverlight and LINQ problems: ‘YourDataClassesDataContext’ does not contain a constructor that takes ‘0’ arguments

After rebuilding my DBML file with SQL metal, my DataContext class no longer has a parameterless constructor. This is due to differences between the was that Visual studio generates the DBML (with SQL metal) and how SQLMetal command-line does by default.

The parameterless constructor simply takes the connection string from web.config rather than requiring one to be passed in as an argument. There may be switches for SQLMetal to handle this, but in the mean time here is a quick solution (which is simply what VS2008 adds when using the DBML builder) :

Add the following method to the DataClasses.designer.cs

public MyDataClassesDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings[“MyConnectionString”].ConnectionString, mappingSource)
{
OnCreated();
}