locked
ASP.NET Dynamic Data Site in Visual Studio 2015 - error "Type is not defined" is global.asax RRS feed

  • Question

  • User794898088 posted

    Hello all,

    I have been beating my head with this for a while now. Here is my process:

    In Visual Studio 2015, I add a new web site to my project, an ASP.NET Dynamic Data web site (Visual Basic).

    I then add an ADO.NET Entity Data Model, named "XYZ", and accept the suggestion to place it in the App_Code folder.

    I go through the model creation and set up the connection to my SQL Server database. The model generates and looks correct. 

    Next, I open Global.asax to uncomment/edit the following line:

    DefaultModel.RegisterContext(GetType(XYZEntities), New ContextConfiguration() With {.ScaffoldAllTables = True})

    From everything I have read, this should be all I need to load the site. However, it consistently tells me: BC30002 Type 'XYZEntities' is not defined'

    I have double-checked the spelling in the Web.config file, and it all lines up.

    What do I need to do to fix this?

    Thank you in advance.

    Saturday, August 6, 2016 5:55 AM

Answers

  • User-330204900 posted

    Hi StoneyB, please check that you are using the Legacy Context in the Entity Data Model the default will be T4 you will need to:

    1. Check from T4 to "Legacy Context"
    2. Delete the T4 files in you Model for this you will need to expand the edmx file
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2016 9:03 AM
  • User794898088 posted

    Ok, I think I solved my issue. I have the mode still set on Legacy Object Context, but I tried something new in the Global.asax:

    Instead of XYZEntities in the DefaultModel.RegisterContext(GetType(XYZEntities), I tried adding the Namespace before the Entities Class name:

    So, that line looks like this: 

    DefaultModel.RegisterContext(GetType(XYZModel.XYZEntities), New ContextConfiguration() With {.ScaffoldAllTables = True})

    Seems to be working fine now. :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2016 11:01 PM

All replies

  • User-330204900 posted

    Hi StoneyB, please check that you are using the Legacy Context in the Entity Data Model the default will be T4 you will need to:

    1. Check from T4 to "Legacy Context"
    2. Delete the T4 files in you Model for this you will need to expand the edmx file
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2016 9:03 AM
  • User794898088 posted

    Hello, and thank you for the reply.

    I am trying again, changing the mode from T4 to Legacy ObjectContext. By the T4 files, I assume that you mean the two .tt files, correct?

    By doing this, the global.asax line: 

    DefaultModel.RegisterContext(GetType(XYZEntities), New ContextConfiguration() With {.ScaffoldAllTables = False})

    Still tells me that Type 'XYZEntities' is not defined.

    Here is my web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2">
          <assemblies>
            <add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
            <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
          <buildProviders>
            <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
          </buildProviders>
        </compilation>
        <httpRuntime targetFramework="4.5.2" />
      </system.web>
      <connectionStrings>
        <add name="XYZEntities" connectionString="metadata=res://*/App_Code.XYZ.csdl|res://*/App_Code.XYZ.ssdl|res://*/App_Code.XYZ.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DARTY-PC\XYY;initial catalog=XYZ;user id=sa;password=*****!;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v13.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>
    </configuration>

    Saturday, August 6, 2016 6:46 PM
  • User794898088 posted

    Ok, I think I solved my issue. I have the mode still set on Legacy Object Context, but I tried something new in the Global.asax:

    Instead of XYZEntities in the DefaultModel.RegisterContext(GetType(XYZEntities), I tried adding the Namespace before the Entities Class name:

    So, that line looks like this: 

    DefaultModel.RegisterContext(GetType(XYZModel.XYZEntities), New ContextConfiguration() With {.ScaffoldAllTables = True})

    Seems to be working fine now. :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 6, 2016 11:01 PM
  • User-330204900 posted

    Glad your sorted, I went for the most common issue first :D

    Sunday, August 7, 2016 8:12 AM