是否有可能在沒有外鍵的2個桌子之間進行連接?HQL加入沒有外鍵在桌子上
編輯:好的,我確信這是可能的,但我不完全確定如何去做。
類
public class Booking
{
public virtual int Id { get; set; }
public virtual Int32 bookingID { get; set; }
public virtual Int32 bookingAdminID { get; set;
}
public class BookingLocation
{
public virtual int Id { get; set; }
public virtual Int32 bookingID { get; set; }
public virtual Int32 locationID { get; set; }
}
映射
public BookingMap()
{
Table("Bookings");
Id(x => x.Id).Column("ID");
Map(x => x.bookingID).Column("BookingID");
Map(x => x.bookingAdminID).Column("BookingAdminID");
}
public class BookingLocation
{
public virtual int Id { get; set; }
public virtual Int32 bookingID { get; set; }
public virtual Int32 locationID { get; set; }
}
我需要做bookingID簡單內連接兩個表的上方。我會怎麼做?
我曾嘗試:
var hql = "select b from Booking as b inner join BookingLocation as bl on b.bookingID = bl.bookingID";
var bookings = session.CreateQuery(hql).List<object[]>();
,但我得到的錯誤:
Semantic exception was unhandled by user code Path expected for join!
[select b from Booking as b inner join BookingLocation as bl on b.bookingID = bl.bookingID]
我採取這種做法,因爲我不能輕易地建立映射這兩個表之間的關係。你需要有一個關係才能進行加入?
感謝您的回答,我試圖使用您的建議,但我一直無法弄清楚語法。我編輯了我原來的文章,你介意重寫你的示例代碼嗎? – iKode 2012-02-03 09:35:36