0

私のSQLクエリ:

select [CompanyId] 
from dbo.Bussiness_Company
where [BussinessId] in (11,12,13)
group by [CompanyId]
having COUNT(distinct [BussinessId])=3

説明: 私はテーブルBussiness_Companyテーブルを持っています:

Business_Company

ID*

ビジネス ID

会社ID

私のデータ:

Id---------BusinessId------------CompanyId

1 ----------10----------------------100

2---------------------11---------------------100

3---------------------12---------------------100

リソールクエリ

会社ID

100

  • 助けてくれてありがとう!

スラブ:

これは私のコードです:

DetachedCriteria detachedCriteria = DetachedCriteria.For<BussinessCompany>();
 detachedCriteria.SetProjection(Projections.Property("Company"));
 detachedCriteria.SetProjection(Projections.GroupProperty("Company"));
 Disjunction disjunction = Restrictions.Disjunction();
 foreach (Bussiness bussiness in list)
 {
   disjunction.Add(Restrictions.Eq("Bussiness", bussiness ));
 }                  detachedCriteria.Add(disjunction).Add(Restrictions.Eq(Projections.CountDistinct<BussinessCompany>(m => m.Bussiness), list.Count));

 IList<Sonomi.Core.BusinessObjects.Bussiness> bussiness =
                    bussinessUnitManager.CreateCriteria().Add(Subqueries.PropertyIn("Id", detachedCriteria)).List
 <Sonomi.Core.BusinessObjects.BussinessUnit>();

 dgrCer.DataSource = bussiness;
 dgrCer.DataBind();
4

1 に答える 1

0

このようなQueryOverコードを試すことができます。

var bussinessIdCount = 3;
var bussinessIds = new[] { 11, 12, 13 };
Bussiness_Company bussinessCompany = null;
session.QueryOver(() => bussinessCompany)
  .WhereRestrictionOn(() => bussinessCompany.BussinessId).IsIn(bussinessIds)
  .Select(Projections.Group(Projections.Property(() => bussinessCompany.CompanyId)))
  .Where(Restrictions.Gt(Projections.CountDistinct(() => bussinessCompany.BussinessId), bussinessIdCount));
于 2012-05-12T12:01:32.170 に答える