【发布时间】:2015-04-08 09:40:33
【问题描述】:
我的模型是这样的
public class Appointment
{
public int AppointmentID { get; set; }
public string AppointmentCode { get; set; }
public string ApplicationUserId { get; set; }
[ForeignKey("ApplicationUserId ")]
public ApplicationUser ApplicationUser { get; set; }
public int PriceId { get; set; }
}
我希望 ApplicationUserId 是可为空的外键,但它不是在表上创建的那样
CONSTRAINT [FK_dbo.Appointment_dbo.IdentityUser_ApplicationUserId] FOREIGN KEY ([ApplicationUserId]) REFERENCES [dbo].[IdentityUser] ([Id]),
谁能指出实现这一目标的正确方法?
注意:我使用的是实体框架代码优先方法
【问题讨论】:
-
也许这会回答你的问题stackoverflow.com/questions/2366854/…
-
这是什么版本的EF?顺便说一句,您可以使用 DbMigration 类中的 Up 方法将自己的逻辑用于模式生成。
标签: c# asp.net-mvc entity-framework ef-code-first