NHibernate Subquery-WhereAll displays "no delegate type" -error

I am trying to create nHibernate-Query with a subquery following the blog post .

My working SQL looks like this:

  SELECT * 
  FROM Product
  WHERE Id IN (
      SELECT p.Id
      FROM Product AS p
      INNER JOIN ProductSupplier AS ps
      ON ps.ProductId LIKE p.Id
      WHERE ps.SupplierProductNumber LIKE '102.02-7100'
      GROUP BY p.Id
  );

      

I need to group by ID because multiple vendors may have the same productNumber

for the same product.

Mine nHibernate

looks like this:

query.WithSubquery.WhereAll(
    p => p.Id ==
        QueryOver.Of<Product>()
        .JoinAlias(x => x.Suppliers, () => productSupplierAlias)
        .Where(() => productSupplierAlias.Product.Id == productAlias.Id)
        .Where(() => productSupplierAlias.SupplierProductNumber == searchtext)
        .Select(p => p.Id));

      

But mine .Select(p => p.Id)

shows

cannot convert lambda expression to type 'nHibernate.Creterian.IProjection []' because it is not a delegate type

+3


source to share


1 answer


I don't think you should be using WhereAll

in this case.

It works:



query.WithSubquery.WhereProperty(p => p.Id)
                    .In(QueryOver.Of<Product>()
                         .JoinAlias(x => x.Suppliers, () => productSupplierAlias)
                         .Where(() => productSupplierAlias.Product.Id == productAlias.Id)
                         .Where(() => productSupplierAlias.SupplierProductNumber == searchtext)
                         .Select(p => p.Id)
                    );

      

+2


source







All Articles