public class Persons
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PersonId { get; set; }
[MaxLength(20)]
public string Name { get; set; }
[MaxLength(11)]
public string Phone { get; set; }
[MaxLength(20)]
public string Wechat { get; set; }
public bool RecvMsg { get; set; }
public bool RecvWx { get; set; }
// 外键(出)
public ICollection<Buildings> Buildings { get; set; }
}
public class Buildings
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int BuildingId { get; set; }
public int ParentId { get; set; }
[Required]
public string Caption { get; set; }
public int DeviceId { get; set; }
[ForeignKey("Persons")]
public int PersonId { get; set; }
[DecimalPrecision(5, 2)]
public decimal MinTem { get; set; }
[DecimalPrecision(5, 2)]
public decima
entity framework code first 设置外键的主从关系问题
最新推荐文章于 2019-04-27 13:57:48 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)