gpt4 book ai didi

nhibernate - QueryOver 与 Join 和 Distinct

转载 作者:行者123 更新时间:2023-12-04 11:30:02 25 4
gpt4 key购买 nike

我使用以下 QueryOver:

var query = searchTermRepository.GetAllOver()
.Where(Restrictions.On<Entities.SearchTerm>(c => c.Text).IsLike(filter.Value, MatchMode.Start))
.Select(Projections.Distinct(Projections.Property<Entities.SearchTerm>(x => x.Contact)))
.Inner.JoinQueryOver(x => x.Contact).Take(100);

这会产生:
SELECT distinct TOP ( 100 /* @p0 */ ) this_.ContactId as y0_
FROM SearchTerm this_
inner join Contact contact1_
on this_.ContactId = contact1_.Id
left outer join Company contact1_1_
on contact1_.Id = contact1_1_.Id
left outer join Person contact1_2_
on contact1_.Id = contact1_2_.Id
left outer join Branch contact1_3_
on contact1_.Id = contact1_3_.Id
left outer join ContactGroup contact1_4_
on contact1_.Id = contact1_4_.Id
WHERE this_.Text like 'koc%%' /* @p1 */

但我想要
SELECT distinct TOP ( 100 /* @p0 */ )  this_.ContactId as y0_, contact1_.*
FROM SearchTerm this_
inner join Contact contact1_
on this_.ContactId = contact1_.Id
left outer join Company contact1_1_
on contact1_.Id = contact1_1_.Id
left outer join Person contact1_2_
on contact1_.Id = contact1_2_.Id
left outer join Branch contact1_3_
on contact1_.Id = contact1_3_.Id
left outer join ContactGroup contact1_4_
on contact1_.Id = contact1_4_.Id
WHERE this_.Text like 'koc%%' /* @p1 */

我想选择所有的联系人属性。

最好的问候, 托马斯

最佳答案

您必须明确指定要投影的所有列。我知道没有办法解决这个问题。

下面是一些使用 QueryOver 的快速代码:

Contact contact = null;

Session
.QueryOver(() => contact)
.SelectList(list => list
.Select(Projections.Distinct(Projections.Property(x => x.Contact)))
.Select(c => c.Id).WithAlias(() => contact.Id)
.Select(c => c.FirstName).WithAlias(() => contact.FirstName)
... and so on

然后,您需要使用 AliasToBean 转换器将其转换为您的对象。

关于nhibernate - QueryOver 与 Join 和 Distinct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6127941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com