【问题标题】:Convert SQL with 'is in' to QueryOver()将带有 'is in' 的 SQL 转换为 QueryOver()
【发布时间】:2011-04-07 20:42:29
【问题描述】:

我需要使用 NHibernate QueryOver 来进行休闲查询。但我的列表有问题。

select * from contact where CountryId = 'xxx' and ContactTypeId in ('aaa', 'bbb')

价值观是 Guid 的。我有一个 List(),其中包含 ContactTypeId (contactTypes) 的 Guid

我已经尝试过 - 但这不起作用:

                var query = contactRepository.GetAllOver()
                    .Where(x => x.Country != null && x.Country.Id == countryId)
                    .WhereRestrictionOn(x => x.ContactType.Id).IsInG(contactTypes);

我希望有人能给我提示如何使用 QueryOver 编写此内容。

【问题讨论】:

  • AndRestrictionOn(p => p.ContactType.Id).IsInG(GuidList) 你得到的错误是什么?

标签: c# sql nhibernate queryover


【解决方案1】:

试试这个

var query = contactRepository.GetAllOver()
                .Where(x => x.Country != null && x.Country.Id == countryId)
                .And(Restrictions.On(c => c.ID).IsIn(contactTypes)

希望对你有帮助。

【讨论】:

  • 我现在用 var query = contactRepository.GetAllOver() .Where(x => x.Country != null && x.Country.Id == countryId) .AndRestrictionsOn(c => 解决了这个问题c.ID).IsIn(contactTypes) 我想,这和你的解决方案一样
  • @t.kehl:是的,是一样的!!
猜你喜欢
  • 2012-06-30
  • 1970-01-01
  • 2011-07-21
  • 2020-11-12
  • 2013-05-10
  • 1970-01-01
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多