[英]data annotations entity framework
我已經創建了這個表:
public string Name { get; set; }
public string Description { get; set; }
[ForeignKey("CityId")]
public City City { get; set; }
public int CityId { get; set; }
現在,我想將CityId設置為null,然后嘗試以下操作:
public string Name { get; set; }
public string Description { get; set; }
[ForeignKey("CityId")]
public City City { get; set; }
public int? CityId { get; set; }
但是,當我在程序包管理器控制台中創建新遷移(add-migration Curso_CityIdNullable)時,生成的遷移為空...
public override void Up()
{
}
public override void Down()
{
}
有幫助嗎? 謝謝
您所做的更改不會將CityId設置為null。 它使它可以為空! 不一樣 您想要將行CityId字段設置為null還是將該字段設置為nullable?
您可以在此處找到ef的數據注釋列表: http : //www.entityframeworktutorial.net/code-first/dataannotation-in-code-first.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.