locked
Cannot register datacontext in Global.asax.cs of ASP.NET Dynamic Data Entities Web Application RRS feed

  • Question

  • Greetings,

    I am creating an ASP.NET Dynamic Data Entities Web Application  and getting error "The type or namespace name 'AdventureWorksModel' could not be found ..."

    Using VS2010, Framework 4.0, EF4.0

    Here is the code where the error occurs (last line) in my Global.asax.cs file:

     

            public static void RegisterRoutes(RouteCollection routes)
            {
                //                    IMPORTANT: DATA MODEL REGISTRATION 
                // Uncomment this line to register an ADO.NET Entity Framework model for ASP.NET Dynamic Data.
                // Set ScaffoldAllTables = true only if you are sure that you want all tables in the
                // data model to support a scaffold (i.e. templates) view. To control scaffolding for
                // individual tables, create a partial class for the table and apply the
                // [ScaffoldTable(true)] attribute to the partial class.
                // Note: Make sure that you change "YourDataContextType" to the name of the data context
                // class in your application.
                DefaultModel.RegisterContext(typeof(AdventureWorksModel), new ContextConfiguration() { ScaffoldAllTables = true });
    

     


    My "AdventureWorks.edmx"  file namespace is "AdventureWorksModel" so not sure what it wants...

    Any insight would be greatly appreciated.

     

     

     

     

    Here is the tutorial I am following:

    http://msdn.microsoft.com/en-us/library/cc488469.aspx



    Best regards, Todd
    Thursday, September 8, 2011 4:49 PM

Answers

  • Hi Todd;

    Open your edmx designer and look in the Model Browser and find the location of the name to use as shown in the image below.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Alan_chen Monday, September 19, 2011 7:39 AM
    Friday, September 9, 2011 3:01 AM
  • Hi Todd,

    Welcome!

    Put your context name here:

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Alan_chen Friday, September 9, 2011 3:44 AM
    • Marked as answer by Alan_chen Monday, September 19, 2011 7:39 AM
    Friday, September 9, 2011 3:43 AM

All replies

  • Hi Todd;

    You are not using the context of the mode you used the namespace. The line in the Global.asax.cs should be as follows :
    DefaultModel.RegisterContext(typeof(AdventureWorksLT_DataEntities), new ContextConfiguration() { ScaffoldAllTables = true });
    


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, September 8, 2011 6:12 PM
  • Hi Fernando,

    Thanks for your help on this.

    I tried "AdventureWorks_DataEntities" and "AdventureworksModel_DataEntities" but same error.

    Ex:

               DefaultModel.RegisterContext(typeof(AdventureWorks_DataEntities), new ContextConfiguration() { ScaffoldAllTables = true });
    

    Know where I might look to determine what the typeof value in statement above should be?


    Best regards, Todd
    Thursday, September 8, 2011 8:54 PM
  • Hi Todd;

    Open your edmx designer and look in the Model Browser and find the location of the name to use as shown in the image below.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Alan_chen Monday, September 19, 2011 7:39 AM
    Friday, September 9, 2011 3:01 AM
  • Hi Todd,

    Welcome!

    Put your context name here:

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Alan_chen Friday, September 9, 2011 3:44 AM
    • Marked as answer by Alan_chen Monday, September 19, 2011 7:39 AM
    Friday, September 9, 2011 3:43 AM
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 14, 2011 6:35 AM
  • I am using the same walkthru and have encountered the same error message during the initial build.  The Model Browser solution provided above does not solve this issue (tho it differs from the text, I used the recommended correction; no joy.) and there is no such Public Partial Class to modify (C# not VB if that has any bearing).

    So, why am I getting this error?

    some vital info

    VS 2010 SP1Rel

    .NET 4.0 SP1Rel

    Tuesday, October 4, 2011 7:47 PM
  • I had the same problem.  I had to use this to get past this error:

    DefaultModel.RegisterContext(

    typeof(AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities), new ContextConfiguration() { ScaffoldAllTables = true });

    HTH.

     


    Michael Graham, MSFT
    Wednesday, November 9, 2011 12:41 PM
  • I tried the solution by Micheal Graham in a Web Site and it worked fine. However, I then attempted to create a Dynamic Web Project rather than a Dynamic Web Site (i.e.: File > New Project > ASP.NET Dynamic Data Entities Web Application), I get error message: "The type or namespace name 'MIMSModel' could not be found"

    Here's the code in my Global.asax.cs file:

    DefaultModel.RegisterContext(typeof(MIMSModel.MIMSEntities), new ContextConfiguration() { ScaffoldAllTables = false });

    In the properties of my edmx file, I have following:

    Entity Container Name: MIMSEntities

    Namespace: MIMSModel

    If the MIMSModel namespace is not the right one, what namespace should I be using?

    BTW I'm using VS 2010 ASP.NET Framework 4 with C#.

    Any suggestions would be greatly appreciated! 


    ~Sonny




    • Edited by sonnymtate Sunday, June 2, 2013 4:58 PM
    Friday, May 31, 2013 1:33 PM
  • I have the same problem with a VB Dynamic Web Project using the following model and code with the ArgumentException error on End Sub below.


    • Edited by TonyFarnum Sunday, June 2, 2013 10:48 AM
    Sunday, June 2, 2013 10:47 AM
  • @Tony:

    Is your solution a web site or a web project? Either way, try replacing Eagle8Entities with Eagle8Model.Eagle8Entities in you Global.asax file. As below:

    DefaultModel.RegisterContext(typeof(Eagle8Model.Eagle8Entities), new ContextConfiguration() { ScaffoldAllTables = true});
    If it a web project and that solves it, I'd like to know, because I can't get work as a web project. I can only get it to work as a web site (there's a difference).

    ~Sonny

    Sunday, June 2, 2013 4:57 PM
  • Instead of "Add New Item" in the folder "App_Code" for modelDB.edmx, add .edmx under your project.

    Right click project name -> Add New Item -> "ADO.Net Entity Data Model". Then put the entity's name, e.g. "AdventureWorksLT_DataEntities" in model.RegisterContext() in Global.asax.cs

    • Proposed as answer by sonnymtate Friday, July 19, 2013 11:28 AM
    Wednesday, July 10, 2013 7:33 PM
  • A simple solution! It worked for me. Thanks AugustaH!

    ~Sonny

    Friday, July 19, 2013 11:33 AM