Ben*_*ual 7 nhibernate join distinct queryover
我使用以下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);
Run Code Online (Sandbox Code Playgroud)
这会创建:
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 */
Run Code Online (Sandbox Code Playgroud)
但我想要
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 */
Run Code Online (Sandbox Code Playgroud)
我想选择所有联系人的属性.
最诚挚的问候,托马斯
您必须显式指定要投影的所有列.据我所知,我无法解决这个问题.
以下是使用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
Run Code Online (Sandbox Code Playgroud)
然后,您需要使用AliasToBean转换器将其转换为您的对象.
| 归档时间: |
|
| 查看次数: |
6727 次 |
| 最近记录: |