问题描述
我为引用
属性之一使用 PropertyRef
。使用 LazyLoad()
,它仍然会执行Select并加载 User
实体,即使我从不击中SalesPerson属性。
订单映射
Id(x => x.Id).GeneratedBy.Native();
引用(x => x.SalesPerson)
.LazyLoad()
.PropertyRef(x => x.Username)
.Column(rsm);
Map(x => x.Title);
订单类
public class Order:BaseEntity
{
...
public virtual User SalesPerson {get;组; }
public virtual string Title {get;组; }
...
}
用户映射
Id(x => x.Id).GeneratedBy.Native();
Map(x => x.Username).Column(login);
用户等级
public class User:BaseEntity
{
public virtual string Username {get;组; }
...
}
生成的顺序映射
pre $
<多对一的类=Project.Userlazy =proxyname =SalesPerson属性-REF = 用户名 >
< column name =rsm/>
< /多对一>
执行代码
var order = session.Get< Order>(1);
Console.WriteLine(order.Title);
有没有办法阻止选择加载用户实体,当我不使用 而不是你问,但也认为与代理多对一不允许你进行类型检查,如果你的子类用户,请参阅 I am using Order Mapping Order Class User Mapping User Class Generated Order Mapping Executing Code Is there anyway to prevent the Select to load the User entity when I'm not using the Has to do with property-ref seeNHibernate creates proxy via session.Load(), but not via Linq or Criteria API And not that you asked, but also consider that many-to-one with proxy does not allow you to do type-checking if you subclass User, seehttp://ayende.com/Blog/archive/2010/01/28/nhibernate-new-feature-no-proxy-associations.aspx 这篇关于Fluent-Nhibernate参考和PropertyRef使用Lazy Load进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
PropertyRef
for one of my References
properties. With LazyLoad()
it still does a Select and loads the User
entity, even though I never "hit" the SalesPerson property.Id(x => x.Id).GeneratedBy.Native();
References(x => x.SalesPerson)
.LazyLoad()
.PropertyRef(x => x.Username)
.Column("rsm");
Map(x => x.Title);
public class Order : BaseEntity
{
...
public virtual User SalesPerson { get; set; }
public virtual string Title { get; set; }
...
}
Id(x => x.Id).GeneratedBy.Native();
Map(x => x.Username).Column("login");
public class User : BaseEntity
{
public virtual string Username { get; set; }
...
}
<many-to-one class="Project.User" lazy="proxy" name="SalesPerson" property-ref="Username">
<column name="rsm" />
</many-to-one>
var order = session.Get<Order>(1);
Console.WriteLine(order.Title);
User
entity?