SetFetchMode呼叫忽略 [英] SetFetchMode call ignored

查看:137
本文介绍了SetFetchMode呼叫忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标准API SetFetchMode调用一个问题,下面的查询:

I have a problem with SetFetchMode call in Criteria API in following query:

DetachedCriteria.For<User>()
                .Add<User>(u => u.Status == UserStatus.Live)
                .CreateAlias("UniqueId", "uid")
                .CreateAlias("Companies", "comp")
                .Add(Restrictions.Disjunction()
                                 .Add(Restrictions.Like("uid.Uid", context.Text, MatchMode.Anywhere))
                                 .Add(Restrictions.Like("comp.Name", context.Text, MatchMode.Anywhere)))
                .SetFetchMode("Companies", FetchMode.Eager));

我的课表:

public class User : EntityBase<int>
{
    public virtual UniqueId UniqueId { get; set; }

    public virtual ISet<Company> Companies { get; set; }
}

public class Company : EntityBase<int>
{
    public virtual string Name { get; set; }
}

public class UniqueId : EntityBase<int>
{
    public virtual string Uid { get; set; }
}

和映射

public sealed class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("users");

        Id(x => x.Id).GeneratedBy.Native().Column("id");

        References(x => x.UniqueId).Column("int_unique_id_ref");

        HasMany(x => x.Companies)
            .KeyColumn("user_id")
            .Inverse()
            .AsSet();
    }
}

public sealed class CompanyMap : ClassMap<Company>
{
    public CompanyMap()
    {
        Table("company");

        Id(x => x.Id).GeneratedBy.Native().Column("id");

        Map(x => x.Name).Column("name");
    }
}

public sealed class UniqueIdMap : ClassMap<UniqueId>
{
    public UniqueIdMap()
    {
        Table("tbl_trading_partner_unique_id");

        Id(x => x.Id).GeneratedBy.Native().Column("int_id");

        Map(x => x.Uid).Column("str_unique_id");
    }
}

但同样让用户列表NHibernate的是查询数据的基础得到公司为每个用户收集后再次。 NHibernate的只是忽略SetFetchMode的电话,因为我已经试着写是这样的:

But after getting users list Nhibernate is quering data base again to get companies collection for each user once again. NHibernate just ignores call of SetFetchMode, because I have tried to write something like this:

.SetFetchMode("NotExistingProp", FetchMode.Eager)

NHibernate的不thows任何异常。

Nhibernate doesn't thows any exceptions.

我也试图设置懒得假的映射,但它也没有帮助。 不知道如何解决它,可有人

I also have tried to set Lazy to false in the mappings, but it also didn't help. Have no idea how to fix it, can somebody

和NHibernate的集装与实体之后。但他仍无视SetFetchMode,我可以写任何东西在那里。

and after that Nhibernate loaded collection with entities. But he is still ignoring SetFetchMode, I can write anything there.

推荐答案

该解决方案是不那么明显。我们已经改变了

The solution is not so obvious. We have changed

.CreateAlias("Companies", "comp")

.CreateAlias("Companies", "comp", JoinType.LeftOuterJoin)

这篇关于SetFetchMode呼叫忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆