加入nhibernate

时间:2012-03-29 09:53:02

标签: c# nhibernate join queryover

我正在使用打击代码加入nhibernate,这很好用。但我不希望在加入之前对两个查询都使用.List,我想在加入后使用.List。我不太了解nhibernate ..请向我提供帮助,我应该在下面的函数中进行更改,先加入数据,然后对其应用.List

 public IEnumerable<PGrp> GetSol()
    {
        _pGrpR = null;
        _pGrp = null;

        QueryOver<Phy, Phy> activePhyQuery = GetDataQuery();

        var phyGrpR = _session.QueryOver(() => _pGrpR)
        .Where(
            Subqueries.WhereProperty<PGrpR>(p => _pGrpR.PhyId).In(
                activePhyQuery))
        .List<PGrpR>();

        IList<PGrp> pGrps = _session.QueryOver(() => _pGrp)
            .Where(x => !x.AC)
            .List<PGrp>();

        var newPGrps = pGrps
            .Join(
                pGrpR,
                p => p.Id,
                x => x.PGrpId,
                (p, x) => p
            ).Distinct().OrderBy(x => x.Name);

        return newPGrps;
    }

由于

1 个答案:

答案 0 :(得分:0)

 PGrpR pGrpR = null;
 IList<PGrp> pGrps = _session.QueryOver(() => _pGrp)
            .Where(x => !x.AC)
            .JoinAlias(pgrps => pgrps.pGrpR, () => pGrpR) // Set real property name
            .OrderBy(() => pGrpR.Name).Asc
            .Select(Projections.Distinct(Projections.Property(() => pGrpR."PropertyForDistinct")))
            .TransformUsing(Transformers.DistinctRootEntity)
            .List<PGrp>();