问题描述:

Im using LINQ to SQL classes from a database. When i try to create a new instance it crashes:

DataLayerDataContext dataLayerDataContext = new DataLayerDataContext();

Stack Trace:

[HttpException (0x80004005): Could not load type 'DataLayerDataContext'.]

System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +8941051

System.Web.UI.WebControls.LinqDataSourceView.get_ContextType() +107

What could be the problem?

网友答案:

If you are keeping your DataContext separate from your working project, then you need to add the connection strings to the database from the DataContext project to the working project's config file as well for it to work.

网友答案:

You can also pass in the connection string to the DataContext constructor as follows:

using(DataLayerDataContext dataLayerDataContext = new DataLayerDataContext("connectionstring")) { Use DataLayerDataContext here. }

网友答案:

I had this problem recently after I moved the dbml to a separate class library (one step in many towards extracting the model from the view). In my case, all of the LinqDataSource's stopped working.

The solution for me was to add the full namespace to the ContextTypeName field in the LinqDataSource. Find and Replace is your friend.

相关阅读:
Top