我有一个看起来像这样的数据库:
Houses
- HouseId
Rooms
- RoomId
HouseRooms
- HouseRoomId
- HouseId
- RoomId
class House
{
[Key]
public virtual int HouseId{ get; set; }
public DbSet<HouseRoom> Rooms{ get; set; }
}
class HouseRoom
{ [Key] public virtual int HouseRoomId{ get; 放; }
public virtual int HouseId{ get; set; }
public virtual int RoomId{ get; set; }
[ForeignKey("RoomId")]
Public Role RoomInfo {get; set;}
}
class Room
{
[Key]
public virtual int RoomId {get; set;}
public string RoomName {get; set;}
}
我只需要 House 实体/模式来加载所有房间记录。注意到 JOIN 表有一个 PK 名称 HouseRoomId 但这不是需要匹配 House 中的键的键。House.HouseId 需要匹配 HouseRoom.HouseId。
我怎样才能让它工作?