[英]Entity framework database mapping
public class Requisitions
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int JobID { get; set; }
[Required]
public string JobNumber { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Department { get; set; }
[Required]
public string Details { get; set; }
[Required]
public DateTime DateOfComplaint { get; set; }
[Required]
public string Period { get; set; }
[Required]
public DateTime EndDate { get; set; }
}
public class Requisitions_Sections
{
public Requisitions Requisitions { get; set; }
[ForeignKey("Requisitions")]
public int JobIDFK { get; set; }
[Required]
public string Section { get; set; }
}
我正在尝试 map 这个外键到 requisition_sections class 但我收到此错误The entity type 'Requisitions_Sections' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types,
The entity type 'Requisitions_Sections' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types,
我为此创建了单独的类。
在 mysql JobIDFK 和部分都应该是主键我不知道如何在 SQL 服务器中执行此操作,这有一对多的关系,一个 jobID 有很多部分。
任何帮助表示赞赏。
public class Requisitions
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int JobID { get; set; }
[Required]
public string JobNumber { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Department { get; set; }
[Required]
public string Details { get; set; }
[Required]
public DateTime DateOfComplaint { get; set; }
[Required]
public string Period { get; set; }
[Required]
public DateTime EndDate { get; set; }
}
public class Requisitions_Sections
{
public Requisitions Requisitions { get; set; }
[ForeignKey("Requisitions")]
public int JobIDFK { get; set; }
[Required]
public string Section { get; set; }
}
我正在尝试 map 这个外键到 requisition_sections class 但我收到此错误The entity type 'Requisitions_Sections' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types,
The entity type 'Requisitions_Sections' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types,
我为此创建了单独的类。
在 mysql JobIDFK 和部分都应该是主键我不知道如何在 SQL 服务器中执行此操作,这有一对多的关系,一个 jobID 有很多部分。
任何帮助表示赞赏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.