我看过文章。 http://fabiomaulo.blogspot.com/2010/03/conform-mapping-components.html
试图在我的项目中重现它并且有奇怪的行为。
我有两个人:
Plan
{
public virtual int Id { get; set; }
public virtual Payer Payer { get; set; }
}
Payer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
映射:
orm.Cascade<Payer, Plan >(CascadeOn.Persist | CascadeOn.Merge);
orm.Cascade<Plan, Payer>(CascadeOn.None);
获取:
mapper.Customize<CarePlan>(cm => cm.ManyToOne(o => o.Payer, x =>
x.Fetch(FetchKind.Join)));
简单得到:
var plan = session.Query<Plan>().Where(c=>c.Id ==
1).SingleOrDefault();
Console.WriteLine(plan.Payer.Name);
我得到了这个问题:
select careplan0_.Id
careplan0_.PayerId
from CarePlans careplan0_
where careplan0_.Id = 1 /* @p0 */
and other query
SELECT payer0_.Id ,
payer0_.Name as Name
FROM Payers payer0_
WHERE payer0_.Id = 2
为什么我有2个查询?如何通过join获取一个查询?
答案 0 :(得分:1)
尝试
var plan = session.Query() 。在哪里(c =&gt; c.Id == 1) .Fetch(x =&gt; x.Player).Eager .SingleOrDefault();
尝试禁用延迟加载,因此默认情况下会急切加载