时间:2010-07-25 22:24:20

标签: nhibernate parent-child

2 个答案:

答案 0 :(得分:1)

用一双新鲜的眼睛坐下来想出来......标签现在由标签问题集(视图)上的标签订购..这使得我的域名中的排序比按孩子数排序更多

    public IList<Tag> GetTop(int numberOfTags)
    {
        using (ITransaction transaction = Session.BeginTransaction())
        {

            DetachedCriteria detachedCriteria = DetachedCriteria.For<Tag>()
                    .CreateCriteria<Tag>(x => x.Questions)
                    .AddOrder<Question>(x => x.Views, Order.Desc)
                    .SetMaxResults(numberOfTags)
                    .SetProjection(Projections.Distinct(Projections.Id()));

            IList<Tag> tags = Session.CreateCriteria<Tag>()
                .SetFetchMode<Tag>(x => x.Questions,FetchMode.Join)
                .Add(LambdaSubquery.Property<Tag>(x => x.Id).In(detachedCriteria))
                .SetResultTransformer(new DistinctRootEntityResultTransformer())
                .List<Tag>();

            transaction.Commit();
            return tags;
        }
    }

答案 1 :(得分:0)