locked
How do I fix a mistake made with DataContext? RRS feed

  • Question

  • User-696641838 posted

    In order to rectify a prior error made to access table data in my SQL server database, I needed to add a primary key to the table.  But then I screwed up by creating a new DataContext with the O/R Designer.  It now appears that there are new DataClasses1.dbml.layout and the designer.cs files that are now under a new DataClasses1.dbml instead of directly in the App_Data folder and the prior files have been deleted.  The code editor for the event handler code in my web page can no longer find any reference to DataClasses1DataContext.  Please tell me what I should do now in order to enable my event handler C# code to use the DataClasses1DataContext.  Thanks.

    Maurice

    Wednesday, December 23, 2009 3:52 PM

Answers

  • User-696641838 posted

    Thanks for responding.  I have decided to do a "Do over", rather than fix the problems that I created in the past.  I have uninstalled VS2008, deleted every associated file, and reinstalled Visual Studio like new.  With the great help that I have received, I expect to do everything right this time.  Thanks.


    Maurice Osborn

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 28, 2009 2:11 PM

All replies

  • User1290601759 posted

    try rename DataClasses1 to  DataClasses1DataContext and drag them to App_Code

    Wednesday, December 23, 2009 7:03 PM
  • User-696641838 posted

    I finally figured out why a new DataClasses1DataContext was created.  This was because I had created additional projects that accessed the same database.  So, I got rid of the extra projects and now I only have the original project with your recommended code for accessing table data in the event handler of a web page.  But I still get error messages that say ‘DataClasses1DataContext’ could not be found.

     

    Within the project folder, there is a “WebApplication1” folder with an “App_Data” folder, among others, as well as DataClasses1.dbml, DataClasses1.dbml.layout, and DataClasses1.designer.cs files.  Within the “App_Data” folder, there is a “Database1“ SQL Server Database Primary Data File and a “Database1_log” transaction log file.  There is also a “Database1.mdf” database in addition to my “Maurice-pc.FreedomDB.dbo” database under “Data Connections” of the Server Explorer window. 

     

    This other database appears to have nothing in it.  Is the DataClasses1DataContext referring to Database1 instead of my database?  Is that why the DataContext cannot be found?  I renamed the DataClasses1.dbml  file to  DataClasses1DataContext as you recommended, but that did not fix the problem, so I changed it back.  Is there anything else that I can do to get DataClasses1DataContext to be recognized by the code editor?

     

    Maurice

    Thursday, December 24, 2009 6:15 PM
  • User1716267170 posted

    Hi Maurice Osborn,

    Can you check the generated source code for LINQ to SQL and get the namespace and DataContext name?

    Thanks.

    Sunday, December 27, 2009 9:55 PM
  • User-696641838 posted

    Thanks for responding.  I have decided to do a "Do over", rather than fix the problems that I created in the past.  I have uninstalled VS2008, deleted every associated file, and reinstalled Visual Studio like new.  With the great help that I have received, I expect to do everything right this time.  Thanks.


    Maurice Osborn

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 28, 2009 2:11 PM
  • User1716267170 posted

    Hope you can resolve the problem :)

    Tuesday, December 29, 2009 4:29 AM