我正在尝试在VS2013中创建一个MVC项目并创建了一些似乎正在生成带有其他列的表的模型。例如,我有以下模型:
namespace JCF_MVC.Models
{
public class Actor
{
public int ID { get; set; }
[Phone(ErrorMessage = "Invalid home phone number entered.")]
[Display(Name = "Home Phone Number")]
[DataType(DataType.PhoneNumber)]
public string HomePhone { get; set; }
[Phone(ErrorMessage = "Invalid mobile/cellular phone number entered.")]
[Display(Name = "Mobile/Cellular Phone Number")]
[DataType(DataType.PhoneNumber)]
public string MobilePhone { get; set; }
[Phone(ErrorMessage = "Invalid work phone number entered.")]
[Display(Name = "Work Phone Number")]
[DataType(DataType.PhoneNumber)]
public string WorkPhone { get; set; }
[Required(ErrorMessage = "A person is required.")]
public virtual Person Person { get; set; }
public virtual Address Address { get; set; }
}
}
为该模型生成的CreateTable语句如下:
CreateTable(
"dbo.Actors",
c => new
{
ID = c.Int(nullable: false, identity: true),
HomePhone = c.String(),
MobilePhone = c.String(),
WorkPhone = c.String(),
Address_ID = c.Int(),
Person_ID = c.Int(nullable: false),
Incident_ID = c.Int(),
})
.PrimaryKey(t => t.ID)
.ForeignKey("dbo.Addresses", t => t.Address_ID)
.ForeignKey("dbo.People", t => t.Person_ID, cascadeDelete: true)
.ForeignKey("dbo.Incidents", t => t.Incident_ID)
.Index(t => t.Address_ID)
.Index(t => t.Person_ID)
.Index(t => t.Incident_ID);
您会注意到我的模型中没有 Incident或Incident_ID ,所以我不清楚为什么要添加列,外键和索引。