1 回答
TA贡献1772条经验 获得超5个赞
您可以尝试在Ping类中为Device添加导航属性,如下所示:
public class Ping
{
public long Id { get; set; }
public long IdDevice { get; set; }
public virtual Device Device { get; set; }//Newly added
public string Request { get; set; }
public string Response { get; set; }
public int RspCode { get; set; }
public DateTime CreatedDateTime { get; set; }
}
然后在Device类中为Ping添加导航属性,如下所示
public class Device
{
public long Id { get; set; }
public string Uid { get; set; }
public Type Type { get; set; }
public Status Status { get; set; }
public virtual List<Ping> Pings { get; set; } //Newly added
}
最后,在OnModelCreating中添加以下映射:
modelBuilder.Entity<Device>().HasMany(d => d.Pings).WithRequired(p => p.Device).HasForeignKey(p => p.IdDevice);
- 1 回答
- 0 关注
- 141 浏览
添加回答
举报