SetFetchMode Lazy不会覆盖ClassMap设置

时间:2015-05-11 12:03:39

标签: c# nhibernate fluent-nhibernate lazy-loading

Criteria SetFetchMode Lazy public class MenuItem : BaseClass<MenuItem> { public virtual int MenuItemId { get; set; } public virtual string Text { get; set; } public virtual IList<MenuItem> Children { get; set; } public virtual MenuItem Parent { get; set; } public MenuItem() { Children = new List<MenuItem>(); } } class MenuItemMap : ClassMap<MenuItem> { public MenuItemMap() { Id(x => x.MenuItemId); Map(x => x.Text); HasMany(x => x.Children).KeyColumn("ParentId").Not.LazyLoad().Fetch.Select(); References(x => x.Parent).Not.LazyLoad().Fetch.Select(); } } using (var session = NHibernateHelper<T>.OpenSession()) { var CC = session.CreateCriteria(typeof(T)); CC.SetFetchMode("Children", FetchMode.Lazy); return CC.List<T>(); } ,但仍然提取所有项目,我该如何解决这个问题?

.classname {
    -webkit-animation: cssAnimation 0s ease-in 5s forwards;
    -moz-animation: cssAnimation 0s ease-in 5s forwards;
    -o-animation: cssAnimation 0s ease-in 5s forwards;
    animation: cssAnimation 0s ease-in 5s forwards;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}
@keyframes cssAnimation {
    to {
    width:0;
    height:0;
    overflow:hidden;
    }
}
@-webkit-keyframes cssAnimation {
    to {
    width:0;
    height:0;
    visibility:hidden;
    }
}

1 个答案:

答案 0 :(得分:2)

我不得不说,这是不可能的。我们的 JAVA 兄弟Hibernate (从中将NHibernate移植到.NET中)似乎有这样的选择:

但NHibernate不支持这一点。 Chek也Override lazy loading behavior 'lazy=false'

我们可以做的是打赌Projections。这样我们就可以组装一个SQL语句并获得一个Transformed对象列表(半填充,取决于所选属性的数量)

16.6. Projections

Here is如何构建深度投影的示例(包括参考文献/多对一)
Here is如何将它们转换为原始映射对象Graph。