我有一个班级,Rate
可以有两个地点;LocationTo
和LocationFrom
。位置应该是页面上的下拉列表。
我的模型如下所示:
public class Rate
{
[Key]
public int Id { get; set; }
public string RateName { get; set; }
public int LocationToId { get; set; }
public int LocationFromId { get; set; }
public virtual Location LocationTo { get; set; }
public virtual Location LocationFrom { get; set; }
}
public class Location
{
[Key]
public int Id { get; set; }
public string LocationName { get; set; }
public virtual ICollection<Rate> Rates { get; set; }
}
我在这里想对了吗?
这是正确的ohlin吗?public virtual Location LocationTo { 得到什么?放; } 做?
public class Location
{
[Key]
public int Id { get; set; }
public string LocationName { get; set; }
[InverseProperty("LocationToId")]
public virtual ICollection<Rate> ToRates { get; set; }
[InverseProperty("LocationFromId")]
public virtual ICollection<Rate> FromRates { get; set; }
}
public class Rate
{
[Key]
public int Id { get; set; }
public string RateName { get; set; }
public int LocationToId { get; set; }
public int? LocationFromId { get; set; }
public virtual Location LocationTo { get; set; }
public virtual Location LocationFrom { get; set; }
}
public class dc : DbContext
{
public DbSet<Location> Locations { get; set; }
public DbSet<Rate> Rates { get; set; }
}