Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Struggling to even get DynamicData example working!

Status
Not open for further replies.

MrMode

Technical User
Aug 28, 2003
195
GB
I have followed the Walkthrough: Creating a New ASP.NET Dynamic Data Web Site Using Scaffolding (
I have created the Dynamic Data website in Visual Studio Express 2012 without problems.

I have created the database model using the Entity Framework without problems.

I have added data using the AdventureWorks.dbml as suggested in the tutorial etc,

Where I am stuck is registering the data model for use by Dynamic Data! In the Global.asax file I have located the commented section that contains RegisterRoutes method, but no matter how hard I cross my fingers, I cannot get the thing working.

Code:
Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    '                     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.
    ' See [URL unfurl="true"]http://go.microsoft.com/fwlink/?LinkId=257395[/URL] for more information on how to register Entity Data Model with Dynamic Data
        Model.RegisterContext(GetType(AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities), _
    New ContextConfiguration() With {.ScaffoldAllTables = True})
        '  DefaultModel.RegisterContext( _
        'New System.Func(Of Object)(Function() DirectCast(New YourDataContextType(), IObjectContextAdapter).ObjectContext), _
        '  New ContextConfiguration() With {.ScaffoldAllTables = False} _
        ')
I noticed that I was using AdventureWorks2012 not the AdventureWorksLT version fo the database so changed the string to:
Code:
   Model.RegisterContext(GetType(AdventureWorks2012_DataModel.AdventureWorks2012_DataEntities), _
    New ContextConfiguration() With {.ScaffoldAllTables = True})

I have no idea what I have or have not done, but it seems unrealistically difficult for a novice to even get started? Can anyone help me get this thing configured so I can at least start to learn how to use it?
 
I have started several times from scratch.

I have been able to set up a Dynamic Data Website, attach a database (NORTHWND.mdf on (LocalDB\v11.0) ), create a Linq to SQL class and change the Global.asax file so that the default.aspx loads with the list of tables.

Code:
  DefaultModel.RegisterContext(GetType(NorthwndDataContext), New ContextConfiguration() With {.ScaffoldAllTables = True})

When I click on a table, this error pops up!

"Unable to cast object of type 'NorthwndDataContext' to type 'System.Data.Objects.ObjectContext'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top