Wrox Programmer Forums
|
BOOK: Professional Visual Studio 2010
This is the forum to discuss the Wrox book Professional Visual Studio 2010 by Nick Randolph, David Gardner, Chris Anderson, Michael Minutillo; ISBN: 9780470548653
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Visual Studio 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2010, 07:58 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default Ch 23 Page 488 Data Context in Global.asax?

I have been floundering around trying to figure out what use for a "data context."

Let's say my database is called "myDB_00" (in the server explorer it shows as ~\sql2008a.myDB_00.dbo).

The Global.asax file notes say that I should use a line such as:

Code:
DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = true });
What I'm trying to figure out is what should replace "YourDataContextType" in this line.

The book uses the data context "AdventureWorksDMDataContext" but there is no explanation as to where this term came from.

I tried "myDB_00DMDataContext" but the IDE underlines this in red and tells me that:
"the type or namespace name "myDB_00DMDataContext" could not be found(are you missing using directive or assembly reference?)"


What should I use as the data context?

Thanks

Ken
 
Old December 6th, 2010, 11:19 AM
Registered User
 
Join Date: Jul 2008
Posts: 8
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hi Ken,

The data context is basically a class that is autogenerated when you create the data model. It sounds like you are missing the step described in the first paragraph of page 488, which describes how to add a new LINQ to SQL class to your project.

If you follow this you will have a data context autogenerated for you. Its name will depend on the name you give the LINQ to SQL class. In the book we named it AdventureWorksDM.dbml, and the autogenerated data context was automatically named AdventureWorksDMDataContext.

I hope this helps.

Regards,
Dave Gardner
The Following User Says Thank You to david_gardner For This Useful Post:
ken evans (December 6th, 2010)
 
Old December 6th, 2010, 12:59 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

Hi Dave,
Thanks for your response. I hope that you can help me to get somewhere with this.
Since elsewhere, I have read that Microsoft has stopped investing in LINQ-toSQL in favour of the Entity Framework approach, the text in the book does not quite fit my situation so I "interpolated" and obviously have got it wrong.

Also, I want to use my SQL Server 2008 DB rather than SQL Server Express.

So I have been trying to devise an appropriate procedure by trial and error whilst using the book as a guide.

1. P 486 says that I will need a database. So I connected one called myDB_00.dbo in Server Explorer.
2. P 486 says use File>New>Project but I want a website so I used File>New Website
3. I chose the ASP.NET Dynamic Data Entities Web Site template. The Global.asax page opens
4. Right Click the project name: C:\...\Test3\
5. Choose Add New Item
6. Choose ADO.NET Entity Data Model (File "Model.edmx" gets added)
7. The IDE asks me if I want to put the model in App_Code folder - Choose Yes.
8. Entity Data Model Wizard: Choose Generate from database.
9. EDM Wizard: My DB connectioon appears with a correct data connection string.
10. Click on checkbox "Save entity connection settings in Web.Config as myDB_00Entities
11: Next: Choose your database Objects/Pluralize/Include FK columns/Model namespace = "myDB_00Model" > Finish
12: The class diagram appears on the screen
13: Global.asax: uncomment line 23
14: Set ScaffoldAllTables = true
15: Replace "YourDataContextType" with "myDB_00ModelDataContext" (Following your example on page 488)
At this point the IDE gives an error: The type or namespace name 'myDB_00ModelDataContext' could not be found. (Are you missing a using directive or an assembly reference?)

Now I'm lost!

One bit I don't understand is the text on page 488 that tells me to "select all tables except the first two and drag them into the designer"
Why not the first two tables?
I tried this with my tables but the IDE gives me the "theta" no go symbol.

Please can you tell me where I have gone wrong and how to make it work?

Thanks
Ken

Last edited by ken evans; December 6th, 2010 at 01:02 PM.. Reason: correct typo
 
Old December 6th, 2010, 01:31 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

OK, I made a little more progress. - er I think :(
As you suggested, I added the Linq-to-SQL Classes and named the file myDB_00DM.dbml

Then I found that the data context: "myDB_00DMDataContext" gets rid of the error message I mentioned in step 15.
One step forward?

But now, when I run the Default.aspx page I get another error:
"Exception Details: System.MissingMethodException: No parameterless constructor defined for this object."
The error points to the global.asax file line 23- the one with the data context in it.

Any clues?

Thanks
Ken
 
Old December 7th, 2010, 04:33 AM
Registered User
 
Join Date: Jul 2008
Posts: 8
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hi Ken,

You almost had it working with your ADO.NET Entity data model. The data context is a little more complicated is this case. Based on the steps you described you will need to specify the following for the data context:

myDB_00Model.myDB_00Entities

The first part of the above is made up of the databasename + the name of the data model (you selected the default Model.edmx).

Once you have done this, and set ScaffoldAllTables = true, you will be able to run the application successfully.

Please also delete the LINQ to SQL class you added to the project. If you wish to use LINQ to SQL you will need to create a new web site and select the "ASP.NET Dynamic Data Linq to SQL Web Site" template instead.

Good luck,
Dave
 
Old December 7th, 2010, 01:50 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

Hi Dave,
That's great - it's all working now - amazing!

Thank you very much for taking the trouble to figure this out for me.
Much appreciated.

To completely close the loop on this, and so that I can replicate it in future, please can you tell me from where you got the data context name and how you figured out the need for the "dot" notation?

Thanks
Ken





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
Calling web page from Global.asax nitinp ASP.NET 1.0 and 1.1 Professional 3 August 27th, 2007 08:25 PM
Context.clearerror() gives an error in Global.asax madhusrp ASP.NET 2.0 Basics 6 April 12th, 2007 02:12 AM
an error in Global.asax when the page is started lovehorse BOOK: ASP.NET Website Programming Problem-Design-Solution 5 October 17th, 2006 07:22 PM
Ch 10 Problem with global.asax Kris BOOK: Beginning ASP.NET 1.0 6 May 11th, 2005 09:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.