Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2011, 12:07 AM
Authorized User
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 14, first 'Try It Out'

Following along chptr 14 while creating my own object model. Has only one table. I did the 'add new item', selecting 'entity data model' as described in the book. Went through entity dialog and it shows me the object model it created from my one table. I saved the .edmx as instructed. In the app_code folder I see the .edmx file but looking at the app_code folder for your PlanetWrox model, it also created a file called PlanetWrox.Designer.vb. I didn't get one of those in my app_code folder. Also after typing in the code in step 9 for the page_load, when I try to apply the 'not defined' fix shown under the code on page 483 the Ctrl+. doesn't give me the choices shown in figure 14-3. What am I doing wrong?

Reply With Quote
  #2 (permalink)  
Old March 16th, 2011, 03:18 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

First, make sure the type you added to App_Code is ADO.NET Entity Data Model and not another type.

Once you've followed the wizard and added the tables, defined the model namespace and so on, open the diagram and click somewhere on a blank spot of the design surface outside any object. Then open the Properties Grid for the diagram and look under Code Generation Strategy. What do you have there? It should be set to Default which uses T4 templates to generate the designer file. Your Grid should look like this:

http://imar.spaanjaars.com/Downloads...tWroxModel.png

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!
Reply With Quote
  #3 (permalink)  
Old March 16th, 2011, 09:02 PM
Authorized User
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default No material differences

My conceptual entity model looks just like the link you provided except for the namespace, entity container name, and the connection string, which I would expect to be different.

Any ideas?

Thanks in advance.
Reply With Quote
  #4 (permalink)  
Old March 17th, 2011, 02:54 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
Any ideas?
Not really.... Somehow it seems that Visual Studio is not generating the Code Behind file for the model. Have you tried recreating it from scratch?

Can you zip up your site and send me a copy for me to look at? You can contact me through my site at http://imar.spaanjaars.com/contact to find out my e-mail address.

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!
Reply With Quote
  #5 (permalink)  
Old March 18th, 2011, 12:36 AM
Authorized User
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default More...

Thanks for your previous suggestion. I was able to remove the Entity stuff and readd and designer.vb code showed up. One wierd thing - the 'factory method' in the vb file didn't have all of the table fields listed in the parameters list (between the '()') and the same table fields were missing in the assignment statments.
Code:
        
Public Shared Function Createpatient_info(ByVal id As Global.System.Int32, ByVal last_name As Global.System.String, ByVal first_name As Global.System.String, ByVal address1 As Global.System.String, ByVal city As Global.System.String, ByVal state As Global.System.String, ByVal zip As Global.System.String, 

' The rest of this list between the () I had to add...

ByVal dob As Global.System.String, ByVal spouse_name As Global.System.String, ByVal insurance_carrier_id As Global.System.String, ByVal HICN As Global.System.String, ByVal pwr_of_attorney As Global.System.String) As patient_info
            Dim patient_info As patient_info = New patient_info
            patient_info.id = id
            patient_info.last_name = last_name
            patient_info.first_name = first_name
            patient_info.address1 = address1
            patient_info.city = city
            patient_info.state = state
            patient_info.zip = zip
'from here down were missing - I had to add...
            patient_info.DOB = dob
            patient_info.spouse_name = spouse_name
            patient_info.insurance_carrier_id = insurance_carrier_id
            patient_info.HICN = HICN
            patient_info.pwr_of_attorney = pwr_of_attorney

            Return patient_info
        End Function
Ok, now for my current issue(s)
1) How do I take a date from a text field and put it in the class for the table? I know it needs a 'cast' of some sort.
2) When I execute the myPatient.SaveChanges() statement it doesn't put anything in the database. Here is the code:

Code:
    Protected Sub bAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bAdd.Click
        Using myPatient As New PrimusEntities()
            'Dim Patient = (From r In myPatient.patient_info
            '             Where r.id = ID
            '             Select r).SingleOrDefault()
            Dim patient As New patient_info()

            patient.last_name = LastName.ToString
            patient.first_name = FirstName.ToString
            patient.middle_name = MidName.ToString
            patient.address1 = Addr1.ToString
            patient.address2 = Addr2.ToString
            patient.city = City.ToString
            patient.state = State.ToString
            patient.zip = Zip.ToString
            'patient.DOB = DirectCast(DOB.ToString, Date)
            patient.spouse_name = SpouseName.ToString
            patient.insurance_carrier_id = InsurCarrierID.ToString
            patient.HICN = HICN.ToString
            patient.pwr_of_attorney = PwrOfAttorney.ToString

            myPatient.SaveChanges()

            Response.Redirect("patient_add.aspx")

        End Using
    End Sub
Reply With Quote
  #6 (permalink)  
Old March 18th, 2011, 05:00 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You shouldn't have to manually update the designer file yourself. The next time you make a change to the model the file is regenerated and your changes are lost. It looks like EF is using a different database than you think? E.g. an older version without these columns that maybe you added recently?

Quote:
1) How do I take a date from a text field and put it in the class for the table? I know it needs a 'cast' of some sort.
Almost. Cast is used to cast between compatible types. In this case, string and date aren't compatible, so you need Convert instead.

Code:
myDate = Convert.ToDateTime(someControl.Text)
Alternatively, you could use the static DateTime.Parse and DateTime.TryParse methods.

Quote:
2) When I execute the myPatient.SaveChanges() statement it doesn't put anything in the database. Here is the code:
Take a look at the section "Hand-Coding Data Access Pages" that starts at page 555.
In step 6 of the TIO on page 559 you find an example that looks similar to yours. A new Review is created which is then added to the Reviews collection with this code:

Code:
 
myEntities.AddToReviews(myReview)
You need to do something liek this with your object as well. Otherwise, you're just newing up a Patient without telling EF of its existence.

BTW: for your latter two questions, you're better off asking them separately in their own thread. This makes it easier for everyone. It'll also give you more viewers. Even better, post them in a generic ASP.NET 4 category as they are not really directly related to the book: http://p2p.wrox.com/asp-net-4-539/

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 page 14 kermit1965 BOOK: Professional ASP.NET MVC 2 6 October 12th, 2010 10:10 AM
chapter 14 vthunder70 BOOK: Beginning ASP.NET 2.0 and Databases 2 October 3rd, 2007 02:11 PM
Chapter 14 example pkumar@ech BOOK: Professional Jakarta Struts 0 November 15th, 2006 09:10 AM
Chapter 14 JonG BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 21st, 2006 10:04 PM
Chapter 14 Mike Smith BOOK: Professional C#, 2nd and 3rd Editions 2 January 4th, 2004 05:13 PM



All times are GMT -4. The time now is 03:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.