Search code examples
sqllinqdynamic-datadatacontext

DataContext Doesn't Exist in Dynamic Data Project?


This is really annoying...and I know it is something extremely simple... 1. I create a new Dynamic Data project. 2. I add a LINQ-to-SQL class and drag and drop some tables onto the class. 3. I open the global.asax.vb and uncomment the line: DefaultModel.RegisterContext(GetType(YourDataContext), New ContextConfiguration() With {.ScaffoldAllTables = True}) I remove YourDataContext and replace it with the DataContext from my LINQ-to-SQL class: DefaultModel.RegisterContext(GetType(NorthwindDataContext), New ContextConfiguration() With {.ScaffoldAllTables = True}) I then try to debug/build/etc. and receive the following error: Type 'NorthwindDataContext' is not defined Why is it not defined? It seems like its not recognizing I created the DBML file.


Solution

  • This is a very strange issue and I am still not sure that I have entirely fixed the issue. But, here is what I think I have learned: 1. If you are creating a New Project in VS2010 you must place the LINQ-to-SQL DBML file in the root project directory. 2. If you are creating a new Web Site in VS2010 you must place the LINQ-to-SQL DBML file in a newly created App_Code directory. 3. If you place it in the wrong place, scrap the project and start over - it doesn't seem to work even if you move the files to the correct location or recreate them in the correct location. Dave.