Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 September 5th, 2011, 11:21 AM
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble with entities framework

I am trying to use the entities framework with my web site and can't get it to work with the GridView control. Here is the code in the code behind for the page including the GridView control:


Code:
Imports NDMDBModel

Partial Class Public_test
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Using myEntities As New NDMDBEntities()
      Dim allReviews = From CompanyNum In myEntities.CompanyNums
                       Order By CompanyNum.Company_num
                       Select CompanyNum
      GridView1.DataSource = allReviews
      GridView1.DataBind()
    End Using
  End Sub
End Class
the text "myEntities As New NDMDBEntities()" is underscored in blue and the text "allReviews" after the Dim statement is highlighted in green.

Any thoughts appreciated.
 
Old September 5th, 2011, 11:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Does the Error List provide more information that just the colors of the exceptions? ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 6th, 2011, 07:50 AM
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with entities framework

Sorry, I should have included them previously.

The error message related to the blue underscored
Code:
 myEntities As New NDMDBEntities()
is " 'Using' operand of type 'NDMDBModel.NDMDBEntities' must implement 'System.IDisposable' "

The green underscored
Code:
 Dim allReviews =
has an error message of "Variable declaration without an 'As' clause, type of object assumed"

My entities connection string also looks slightly different than the PlanetWrox example. It ends with
Code:
 multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I appear to have some problem in the entities diagram with plurals. Although I have the box checked to use plurals in naming, I don't always get them. I think it is related to whether I declare a primary key with autonumbering. I am investigating that more.

Thanks for any inisghts you have.

Nelson Miller
 
Old September 6th, 2011, 02:03 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Sounds like your model isn't in order. Try this:

1. Comment out the code that results in the errors

2. Check your model and save all changes.

3. Right-click the Project in the Solution Explorer and choose Build or Rebuild.

4. Fix any errors listed in the Error List.

5. Try the code again.

For EF to work, your tables must have a primary key (e.g. at least one column needs the key icon in front of it). From an EF point of view, this doesn't have to be an identity. For the Planet Wrox web site the code assumes it's an identity though. You need to make these changes in the database before you create the EF model. If you make changes later you need to recreate or update the model.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 6th, 2011, 04:39 PM
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with entities framework

Thanks for this Imar. Related question: some of my tables in SQL Server have names that include an underscore (example: Acttab_master). Any problem with this naming convention?

Regards,

Nelson
 
Old September 6th, 2011, 04:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Nelson,

No, as far as I know you should be OK with an underscore. I don't like it personally, but that's a different topic.... ;-)

Did you manage to fix the problem?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 6th, 2011, 05:27 PM
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with entities framework

Haven't tried it yet but will let you know.

Appreciate all your help.
 
Old September 7th, 2011, 09:23 AM
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with entities framework

Imar, deleted the edmx file and related connection string in the web.config file. Tried to recreate it and got 46 error messages (see below). Any quick thoughts? If not, I will try to work around by not using the entities framework approach.

Regards,

Nelson

1 Namespace or type specified in the Imports 'System.Data.Objects' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
2 Namespace or type specified in the Imports 'System.Data.Objects.DataClasses' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
3 Namespace or type specified in the Imports 'System.Data.EntityClient' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
4 Type 'EdmSchemaAttribute' is not defined.
5 Type 'EdmRelationshipAttribute' is not defined.
6 Type 'ObjectContext' is not defined.
7 Type 'EntityConnection' is not defined.
8 Type 'ObjectSet' is not defined.
9 Type 'ObjectSet' is not defined.
10 Type 'ObjectSet' is not defined.
11 Type 'ObjectSet' is not defined.
12 Type 'EdmEntityTypeAttribute' is not defined.
13 Type 'EntityObject' is not defined.
14 Type 'EdmScalarPropertyAttribute' is not defined.
15 'ReportPropertyChanging' is not declared. It may be inaccessible due to its protection level.
16 'StructuralObject' is not declared. It may be inaccessible due to its protection level.
17 'ReportPropertyChanged' is not declared. It may be inaccessible due to its protection level.
18 Type 'EdmScalarPropertyAttribute' is not defined.
19 'ReportPropertyChanging' is not declared. It may be inaccessible due to its protection level.
20 'StructuralObject' is not declared. It may be inaccessible due to its protection level.
21 'ReportPropertyChanged' is not declared. It may be inaccessible due to its protection level.
22 Type 'EdmScalarPropertyAttribute' is not defined.
23 'ReportPropertyChanging' is not declared. It may be inaccessible due to its protection level.
24 'StructuralObject' is not declared. It may be inaccessible due to its protection level.
25 'ReportPropertyChanged' is not declared. It may be inaccessible due to its protection level.
26 Type 'EdmScalarPropertyAttribute' is not defined.
27 'ReportPropertyChanging' is not declared. It may be inaccessible due to its protection level.
28 'StructuralObject' is not declared. It may be inaccessible due to its protection level.
29 'ReportPropertyChanged' is not declared. It may be inaccessible due to its protection level.
30 Type 'EdmRelationshipNavigationPropertyAttribute' is not defined.
31 Type 'IEntityWithRelationships' is not defined.
32 Type 'IEntityWithRelationships' is not defined.
33 Type 'EntityReference' is not defined.
34 Type 'IEntityWithRelationships' is not defined.
35 Type 'IEntityWithRelationships' is not defined.
36 Type 'EdmEntityTypeAttribute' is not defined.
37 Type 'EntityObject' is not defined.
38 Type 'EdmScalarPropertyAttribute' is not defined.
39 'ReportPropertyChanging' is not declared. It may be inaccessible due to its protection level.
40 'StructuralObject' is not declared. It may be inaccessible due to its protection level.
41 'ReportPropertyChanged' is not declared. It may be inaccessible due to its protection level.
42 Type 'EdmScalarPropertyAttribute' is not defined.
43 'ReportPropertyChanging' is not declared. It may be inaccessible due to its protection level.
44 'StructuralObject' is not declared. It may be inaccessible due to its protection level.
45 'ReportPropertyChanged' is not declared. It may be inaccessible due to its protection level.
46 Type 'EdmRelationshipNavigationPropertyAttribute' is not defined.
47 Type 'EntityCollection' is not defined.
48 Type 'IEntityWithRelationships' is not defined.
49 Type 'IEntityWithRelationships' is not defined.
 
Old September 7th, 2011, 09:27 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

A few questions to help figure out what's going on:

1. What's the physical folder of your web site on disk?

2. What's the name of the SQL Server database and where is it located on disk?

3. Where do you create this EDMX file? E.g. in which folder?

4. Is this a Web Site Project or a Web Application Project?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 7th, 2011, 10:16 AM
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with entities framework

Imar,

1. What's the physical folder of your web site on disk?
C:\BegASPNET\ND_Miller

2. What's the name of the SQL Server database and where is it located on disk?
C:\BegASPNET\ND_Miller\App_Data\NDMDB.mdf

3. Where do you create this EDMX file? E.g. in which folder?
C:\BegASPNET\ND_Miller\App_Code

4. Is this a Web Site Project or a Web Application Project?
I believe it is a project - On opening VWD it refers to the file as a project. Other than that I am not sure how to confirm. I think I followed the instructions in the book to work with project and not applications

P.S. - I realize you can't spend unlimited time on this so don't hesitate to redirect me if appropriate.

Regards,

Nelson





Similar Threads
Thread Thread Starter Forum Replies Last Post
resolving entities stolte XSLT 5 February 24th, 2011 01:31 PM
changing host server framework 2.0 from framework jay_vijesh ASP.NET 1.x and 2.0 Application Design 1 September 11th, 2006 02:18 PM
How use framework components in compact framework? r_bazghaleh C# 0 February 19th, 2006 05:05 AM
Entities as String muki XSLT 3 November 12th, 2005 12:15 PM
Entities safin XSLT 1 November 7th, 2005 04:59 AM





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