这是我的简单С#代码:
var chests = _session.CreateCriteria<GameCharacterChest>()
.CreateAlias("GameCharacterEquipments", "equip", JoinType.InnerJoin)
.Add(Restrictions.Eq("GameCharacterId", characterId))
.List<GameCharacterChest>();
foreach (var chest in chests)
{
var equip = chest.GameCharacterEquipments.FirstOrNull();
if (equip != null)
{
var slot = (equip as GameCharacterEquipment).GameCharacterSlotTypeId;
}
}
在foreach
循环中 NHibernate 将 SQL 查询发送到我的数据库。为什么?GameCharacterEquipment
内部连接在第一个查询中已请求的信息。我有流利的地图。