locked
VS2012 RTM - Context type is not supported with ASP.NET dynamic data RRS feed

  • Question

  • User1291592770 posted
    • Creating a new ASP.NET dynamic date project with VS 2012 RTM.
    • Add new EF model
    • fix the RegisterContext line in Global.asx

    run debug and get the error.

    I beleive Microsoft didn't debug well prior to release with Dynamic data..............

    Wednesday, September 12, 2012 10:17 AM

Answers

  • User-330204900 posted

    Hi Uniprof, you have to change the code generation type in the EF data model.

    1. Delete the TT files from the model

    2. Change the "Code Generation Stategy" to "Default"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2012 4:42 AM
  • User-514671131 posted

    I found the problem with my database was a database table named Site which was conflicting the default Site class.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 9, 2012 7:23 AM
  • User-514671131 posted

    sjnaughton I was able to find another way without having to delete the TT files or change Code Generation to Default.  

    Here is the Link: http://blog.davidebbo.com/2011/01/using-dynamic-data-with-ef-code-first.html

    This is a direct copy of the portion that works:

    Approach #1: dig the ObjectContext out of the DbContext

    The workaround is quite simple. In your RegisterRoutes method in global.asax, just add the following code (you’ll need to import System.Data.Entity.Infrastructure and the namespace where your context lives):

    1
    2
    3
    4
    public static void RegisterRoutes(RouteCollection routes) {
    DefaultModel.RegisterContext(() => {
        return ((IObjectContextAdapter)new BlogContext()).ObjectContext;
    }, new ContextConfiguration() { ScaffoldAllTables = true });

    So what this is really doing differently is provide a Lambda that can dig the ObjectContext out of your DbContext, instead of just passing the type to the context directly.

    Hope this help someone else looking.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2012 5:22 PM
  • User-769878331 posted

    Had same issue, resolved by importing the namespace at top of global.asax

    The namespace is defined in the Namespace property of the ConceptualEntityModel, i.e. your edmx file.

    <%@ Import Namespace="AdventureWorksLT2012Model" %>

    Now it works!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 19, 2013 3:45 PM

All replies

  • User3866881 posted

    Hello,

    Would you mind sending me your code sample package so as to let me check with that?

    My email is:v-dedong@microsoft.com

    Please make sure that your package must be type of zip.

    Your Email title should be ful-filled with your issue's title, in the body please attach your sample as well as your issue's URL.

    Reguards!

    Thursday, September 13, 2012 9:06 PM
  • User-330204900 posted

    Hi Uniprof, you have to change the code generation type in the EF data model.

    1. Delete the TT files from the model

    2. Change the "Code Generation Stategy" to "Default"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2012 4:42 AM
  • User707634511 posted

    This fixed my problem which was not being able to create a dynamic data website, create an entitymodel for some tables and just put the type into the commented line in the Global.asax file, change scaffold to true and then go, like I did it vs 2010. Now I can do that, if I just add what u wrote to the list. THX!

    I am still worried that I don't have the linq to sql version of the template any longer. Sure there is a way to get it working, but since it's not there anymore I think it's time to change to entitites. I just still think there are so many things I can't do with linq to enitites as easily as in linq to sql. :'(.

    Saturday, October 27, 2012 12:52 PM
  • User-514671131 posted

    I seem to have the same problem with my application.  I implemented what you suggested.  Then I choose Generate Database from Model.  The error I am getting now is:

    Error 4 The type or namespace name 'Vita_DataEntities' could not be found (are you missing a using directive or an assembly reference?) D:\WebSites\VITA-DYN\Global.asax 25 45 VITA-DYN(1)

    Any help would be appreciated.

    Tuesday, November 6, 2012 5:18 PM
  • User-330204900 posted

    Hi MClayton. this is the correct fix can you delete you data model and then recreate, after you have you model follow my steps and all should be good.

    Wednesday, November 7, 2012 9:10 AM
  • User-514671131 posted

    I started this over again and I also tried the Adventure Works 2012 database and I get the same results after I delete TT files and change Code Generation to Default and then Generate Database from Model.  I must be doing something wrong, but I have no idea what it could be.  Below is my error.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'AdventureWorksLT2012_DataEntities' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 24:         // See http://go.microsoft.com/fwlink/?LinkId=257395 for more information on how to add and configure an Entity Data model to this project
    Line 25:         //DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });
    Line 26: DefaultModel.RegisterContext(typeof(AdventureWorksLT2012_DataEntities), new ContextConfiguration() { ScaffoldAllTables = true }); Line 27: 
    Line 28:         // The following statement supports separate-page mode, where the List, Detail, Insert, and 


    Source File: d:\WebSites\AdventureWorks2012\Global.asax Line: 26


    Wednesday, November 7, 2012 12:39 PM
  • User-330204900 posted

    Just Testing now

    Wednesday, November 7, 2012 1:03 PM
  • User-330204900 posted

    Hi there MClayton, did you delete all the .tt file entitis and Context?

    P.S. you do not need the update model from database step it just works.

    Wednesday, November 7, 2012 1:09 PM
  • User-514671131 posted

    sjnaughton, 

    Thanks for your time it looks as if there is a couple of things I was doing wrong:

    1.  I needed to create as a Project and not a website, was able to get this to work with AdventureWork2012LT after going through your process.

    2. Seems there is something wrong when I use my database specifically.

    Wednesday, November 7, 2012 1:52 PM
  • User-330204900 posted

    Can you send me the schema? so I can replicate?

    Thursday, November 8, 2012 6:01 PM
  • User-514671131 posted

    I found the problem with my database was a database table named Site which was conflicting the default Site class.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 9, 2012 7:23 AM
  • User-514671131 posted

    sjnaughton I was able to find another way without having to delete the TT files or change Code Generation to Default.  

    Here is the Link: http://blog.davidebbo.com/2011/01/using-dynamic-data-with-ef-code-first.html

    This is a direct copy of the portion that works:

    Approach #1: dig the ObjectContext out of the DbContext

    The workaround is quite simple. In your RegisterRoutes method in global.asax, just add the following code (you’ll need to import System.Data.Entity.Infrastructure and the namespace where your context lives):

    1
    2
    3
    4
    public static void RegisterRoutes(RouteCollection routes) {
    DefaultModel.RegisterContext(() => {
        return ((IObjectContextAdapter)new BlogContext()).ObjectContext;
    }, new ContextConfiguration() { ScaffoldAllTables = true });

    So what this is really doing differently is provide a Lambda that can dig the ObjectContext out of your DbContext, instead of just passing the type to the context directly.

    Hope this help someone else looking.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2012 5:22 PM
  • User-769878331 posted

    Had same issue, resolved by importing the namespace at top of global.asax

    The namespace is defined in the Namespace property of the ConceptualEntityModel, i.e. your edmx file.

    <%@ Import Namespace="AdventureWorksLT2012Model" %>

    Now it works!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 19, 2013 3:45 PM
  • User-823707336 posted

    I am experiencing the same problem using VS2012 update 1 and AdventureworksLT2012. 

    I followed the walkthrough at :http://msdn.microsoft.com/en-us/library/cc488469(v=vs.100).aspx

    It was necessary to use:

            DefaultModel.RegisterContext(() =   {   return ((IObjectContextAdapter)new AdventureWorksLT2012_DataEntities()).ObjectContext; },new ContextConfiguration() { ScaffoldAllTables = true });

     

    However, just compiling with this will fail because IObjectContextAdapter  is not defined.

    I had to add: <%@ Import Namespace="System.Data.Entity.Infrastructure" %> to global.asax

    thanks to: http://stackoverflow.com/questions/16146423/dynamic-data-iobjectcontextadapter-missing-reference

    which had the answer in the most recent reply.

    Following this, it finally compiled and worked, but this took a long time to dig out!

     

     

    Friday, April 26, 2013 10:48 AM
  • User16503030 posted

    I have a similar problem:

    I have a new project created using Visual Studio 2013 with an ADO.NET Entity Data Model (EF6).

    Now I have to use some Dynamic Data function (like access to MetaTable object), so I add this code:

    MetaModel model = new MetaModel();

    model.RegisterContext(() => { return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)new KiwiJuiceEntities()).ObjectContext; }, new ContextConfiguration() { ScaffoldAllTables = true });

    but I've got this error: Type of context 'System.Data.Entity.Core.Objects.ObjectContext' is not supported

    It's easy to reproduce:

    Open VS 2013 -> Create a new Dynamic Data site (from old VS2012 templates) -> Create a new ADO.NET Model and change global.asax with ModelName, Run... and surprise!

    But if I use your solution I have problem with the old namespace used by Entity Framework... there is a solution for VS2013+DynamcData+EF?

    Thursday, December 12, 2013 12:58 PM
  • User-330204900 posted

    Hi EF6 is not supported for Dynamic Data and Web Forms for that matter with DbContext you will need to change the Code Generation to Legacy and delete the tt files then it should work.

    Thursday, December 12, 2013 2:20 PM
  • User16503030 posted

    Thx for your reply! I have tryed deleting .tt and changing generation strategy but if I do that with a new project created from vs2013 I have problem with old system.data.objects namespace. Vs2013 use the new entityframework.dll and not system.data.objects.dll...

    Following your solution using the template that creates visual studio 2013 should create the edmx model, delete the. Tt, change the strategy of generation and then, by hand, change the references System.Data.Entity with new System.Data. Entity.Core [...]. But every time I change the edmx I have to re-apply the change of namespace ...

    there is no solution without downgrading ef?

    UPDATE: I have just tried using EF5 and all works without remove .tt files and using T4 as code generation strategy...

    Thursday, December 12, 2013 2:28 PM
  • User-330204900 posted

    Yes that would still be an issue.

    Thursday, December 12, 2013 6:03 PM
  • User16503030 posted
    do you know if or when dynamic data will support EF6? Whereas in VS2013 microsoft 'hidden' template to create a new dynamic data website I doubt that there is a plan for future development ...
    Friday, December 13, 2013 7:35 AM
  • User-330204900 posted

    The ASP.Net team tell me it will around January, what we need is an updated EntityDataSource that supports EF6 :)

    Friday, December 13, 2013 12:38 PM
  • User16503030 posted

    Perfect!

    Thanks!

    Friday, December 13, 2013 1:08 PM
  • User713553159 posted

    Dear Sjnaugthon.. ned your help to solve the sam issue

    VS2012 Profesional - Dynamic project,

     // The following registration should be used if YourDataContextType does not derive from DbContext

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

    Error 1 The type or namespace name 'AdventureWorksLT2012_DataModel' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Oktii\Documents\Visual Studio 2012\WebSites\DinamicaDeus\Global.asax 33 45 DinamicaDeus

    I try all the suggestion , tt elimianated, model into de default o be on the root, .. without sucess... I knoiw can be a easy issue but can.

    OF

    pd happy 2014

    Thursday, January 2, 2014 4:12 PM
  • User-330204900 posted

    Hi Octavio, go to mu blog (in my signature) and get my e-mail from there and e-mail me direct :) we should be able to fix it quite quickly.

    Friday, January 3, 2014 5:17 AM