Answered by:
Problem with RegisterContext

Question
-
User1432731054 posted
So i was trying to do the dynamic data tutorial (the first one) from the videos but with my own database and i get:
Unable to cast object of type 'PBODataContext' to type 'System.Data.Objects.ObjectContext'.
I added the PBO.dbml to my App_Code folder and then uncommented the line he mentions and changed it to this:
model.RegisterContext(GetType(PBODataContext), New ContextConfiguration() With {.ScaffoldAllTables = True})
The site compiles and runs and i can see my two tables, but when i click on either i get the above error. Do i need to do something special with my table or what?
Thursday, October 9, 2008 11:21 AM
Answers
-
User-1005219520 posted
This is usually because you created a Dynamic Data Entities Web site (which must use ADO Entity Framework (EF)) - but you used L2S. The Entity Data Model is defined as System.Data.Objects.ObjectContext - but when you try to cast your L2S model (which is of type System.Data.Linq.DataContext ) you get the exception. Create the web site and select "Dynamic Data Web Site"
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 9, 2008 2:42 PM
All replies
-
User-330204900 posted
Once you've added the DBML file to the App_Code folder you need to open it up in the designer it will say no connection string and will use from L2S classes save and then it will work. This being a file based website (App_Code folder) if your designer.cs file has a namespace surrounding the classes then you will either need to remove it or specify it explicitly
i.e. if your namespace is Testing then you would specify Testing.PBODataContext
Hope this makes sense [D:]
Thursday, October 9, 2008 12:06 PM -
User-1005219520 posted
This is usually because you created a Dynamic Data Entities Web site (which must use ADO Entity Framework (EF)) - but you used L2S. The Entity Data Model is defined as System.Data.Objects.ObjectContext - but when you try to cast your L2S model (which is of type System.Data.Linq.DataContext ) you get the exception. Create the web site and select "Dynamic Data Web Site"
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 9, 2008 2:42 PM -
User-330204900 posted
oops! i did'nt see this Unable to cast object of type 'PBODataContext' to type 'System.Data.Objects.ObjectContext'. before it disappeard as soon as the page appeared [:$]
Rick is right [:D]
Thursday, October 9, 2008 3:15 PM -
User1432731054 posted
Ok, my bad...I knew it had to be something simple. Thank you very much.
Thursday, October 9, 2008 3:29 PM