我有以下型号:
public class FlatMap : ClassMap<Flat>
{
public FlatMap()
{
Id(m => m.FlatID).GeneratedBy.Identity();
Map(m => m.Name);
Map(m => m.Notes);
Map(m => m.Released);
}
}
public class BuildingMap : ClassMap<Building>
{
public BuildingMap()
{
Id(i => i.BuildingID).GeneratedBy.Identity();
Map(m => m.Name);
HasMany<Flat>(m => m.Flats).Cascade.All().KeyColumn("BuildingID").Not.LazyLoad();
}
}
public class ContractMap : ClassMap<Contract>
{
public ContractMap()
{
Id(m => m.ContractID).GeneratedBy.Identity();
Map(m => m.Amount);
Map(m => m.BeginIn);
Map(m => m.EndIn);
References(m => m.RentedFlat);
}
}
如何使用流畅的nhibernate进行以下查询?
Select * From Contract
Inner Join Flat On Contract.RentedFlatID = Flat.ID
Inner Join Building On Building.BuildingID = Flat.BuildingID
Where Building.BuildingID = @p0
特别是从Flat到Building没有参考?我不希望它是!
当然是我正在谈论的参考,以便能够做这样的事情
var criteria = session.CreateCriteria<Contract>().CreateCriteria ("RentedFlat").CreateCriteria ("Building"/*there is no such property in Flat class*/);
答案 0 :(得分:0)
我将一个属性BuildingID添加到Flat类,并将映射类修改为:
Map(m => m.BuildingID);
现在我可以进行以下查询:
criteria.CreateCriteria("RentedFlat")
.Add(Restrictions.Eq("BuildingID", selectedBuilding.BuildingID));