【发布时间】:2011-04-23 14:34:23
【问题描述】:
我有一个简单的类,叫做申请人。我正在尝试使用实体框架添加模板控制器,申请人作为我的模型类,以及一个新的数据上下文。
每次尝试创建控制器时,我都会收到一个错误对话框,显示“无法检索 'MyNameSpace.Models.Applicant' 的元数据。生成 'ScaffoldingConnectionFactory' 时出错。请尝试重建您的项目。”
重建无济于事。
这是我的模型类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace MyNameSpace.Models
{
public class Applicant
{
public int ApplicantId { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
public string MiddleInitial { get; set; }
[Required]
public string Phone { get; set; }
[Required]
public string EmailAddress { get; set; }
[Required]
[DataType(DataType.Date)]
public string DateOfBirth { get; set; }
public virtual Ethnicity Ethnicity { get; set; }
public virtual Race Race { get; set; }
}
public class Ethnicity
{
public int EthnicityId { get; set; }
public string Type { get; set; }
}
public class Race
{
public int RaceId { get; set; }
public string Type { get; set; }
}
}
我觉得我错过了一步,但我不能把手指放在它上面。
【问题讨论】:
标签: entity-framework asp.net-mvc-3 ef-code-first