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?