Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Professional ASP.NET MVC 5
|
BOOK: Professional ASP.NET MVC 5
This is the forum to discuss the Wrox book Professional ASP.NET MVC 5 by Jon Galloway, Brad Wilson, K. Scott Allen, David Matson; ISBN: 978-1-118-79475-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 5 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 January 6th, 2015, 07:04 PM
Registered User
 
Join Date: Nov 2014
Posts: 8
Thanks: 4
Thanked 1 Time in 1 Post
Question What do you do if you've left stuff out of the model, when generating controllers?

I've read enough of this book so that I feel like I can start working on an implementation of my own. My application is a simple one, to track interviews I do and the companies I do them with. (I have to get just so far into the book before I feel I've got enough to try and do my own. Don't worry, I'll finish the book.) I've already got an existing database with some data in it, so I choose to use EF with existing data. And as I understand it I've got to create my own model classes that reflect the tables in my database, so that is what I've done. What I did was first create the model classes for each of my lookup tables and then I started on one of my data tables, named Interviews. Here's the CREATE TABLE definition so that you'll know what I'm talking about:

Code:
CREATE TABLE [dbo].[Interviews](
	[InterviewID] [int] IDENTITY(1,1) NOT NULL,
	[CompanyID] [int] NOT NULL,
	[UserID] [int] NOT NULL,
	[InterviewDateTime] [datetime] NOT NULL,
	[InterviewerNameAndTitle] [nvarchar](256) NULL,
	[InterviewerPhone] [varchar](50) NULL,
	[InterviewerEmail] [nvarchar](128) NULL,
	[InterviewTypeID] [int] NOT NULL,
	[MailiingAddressCityStateZip] [nvarchar](256) NULL,
	[DateThankYouSent] [date] NULL,
	[Comments] [nvarchar](max) NULL,
 CONSTRAINT [PK_Interviews] PRIMARY KEY CLUSTERED 
(
	[InterviewID] ASC
)WITH (PAD_INDEX  = OFF) ON [PRIMARY]
) ON [PRIMARY]
And here is the associated model class:

Code:
public class Interview
{
	[Key]
	public virtual int InterviewID { get; set; }

	[Required]
	public virtual int CompanyID { get; set; }

	[Required]
	public virtual int UserID { get; set; }

	[Required]
	[DataType(DataType.DateTime)]
	[Display(Name="Interview Date and Time")]
	public virtual DateTime InterviewDateTime { get; set; }

	[StringLength(256)]
	[Display(Name="Interviewer's name and possibly title")]
	public virtual string InterviewerNameAndTitle { get; set; }

	[StringLength(50)]
	[DataType(DataType.PhoneNumber)]
	[Display(Name="Interview's phone number")]
	public virtual string InterviewerPhone { get; set; }

	[StringLength(128)]
	[DataType(DataType.EmailAddress)]
	[Display(Name="Interviewer's email address")]
	public virtual string InterviewerEmail { get; set; }

	[Required]
	public virtual int InterviewTypeID { get; set; }

	[StringLength(256)]
	[Display(Name="Interview Address (street, city, state, zipcode)")]
	public virtual string MailiingAddressCityStateZip { get; set; }

	[DataType(DataType.Date)]
	[Display(Name="Date thank you sent")]
	public virtual DateTime DateThankYouSent { get; set; }

	public virtual string Comments { get; set; }
}
The problem I've created for myself is that I don't have any navigation properties in the Interview class for either Company or User. I've got both lookup tables and classes, but no navigation properties as described in chapter 4. I'm kicking myself for having made that mistake, believe me! But now I wonder, what do I do with the controller and views I've generated? Do I just delete them from the project, make the necessary modifications to the Interview class and then re-generate them? Or do I do something else?
 
Old January 7th, 2015, 04:25 AM
Wrox Author
 
Join Date: Oct 2006
Posts: 36
Thanks: 1
Thanked 5 Times in 5 Posts
Default

The simplest approach is to just delete the controller and views and re-scaffold everything. If you've made modifications to some of the views that you don't want to lose, you can delete individual views and re-scaffold them individually by right-clicking in the specific action (e.g. Details(), Edit()) and selecting scaffold view - or by using the keyboard shortcut ctrl-m, ctrl-v.
The Following User Says Thank You to JonGalloway For This Useful Post:
rfalanga (January 7th, 2015)
 
Old January 7th, 2015, 04:23 PM
Registered User
 
Join Date: Nov 2014
Posts: 8
Thanks: 4
Thanked 1 Time in 1 Post
Default

Thank you Jon, that's what I want to know!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 14 generating entity model AlanWheeler BOOK: Beginning ASP.NET 4.5 : in C# and VB 2 April 30th, 2014 07:51 AM
Chapter 14 : Mapping data model to an object model robochrish BOOK: Beginning ASP.NET 4 : in C# and VB 8 March 5th, 2013 09:52 AM
Controllers chillbill7 BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 1 March 16th, 2009 10:13 AM
controllers/welcome.php throwing error modelreject BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 4 March 16th, 2009 10:09 AM
Rails: move flash between controllers ciderpunx Ruby 2 March 7th, 2006 08:25 PM





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