Domanda

I am having trouble converting what is a somewhat simple query into an LLBLGen Pro dynamic query. I need to convert something like following SQL (but I'll be passing in values for the region, the id to check and the required names):

SELECT  Parent.Id
FROM    Parent INNER JOIN Child
ON      Child.ParentId = Parent.Id
WHERE   Parent.Region = '1'
    AND Parent.Id IN (1, 2, 3, 4, 5)
GROUP BY
        Parent.Id
HAVING  SUM(CASE WHEN child.Name IN ('Required1', 'Required2', 'Required3') THEN 1 ELSE 0 END) != 3

But, I'm having a hard time converting the Having clause into the LLBL equivalent.

This is what I have so far:

var q = qf.Create()
          .From(qf.ParentView
            .InnerJoin(qf.ChildView)
                .On(ChildViewFields.Id == ParentViewFields.ParentId))
          .Where((ParentViewFields.Region == _region)
            .And(ParentViewFields.Id.In(_checkIds)))
          .Select(() => ParentViewFields.Id.ToValue<string>())                      
          .GroupBy(ParentViewFields.Id)
          .Having( ??? )

Any help would be greatly appreciated. I'm open to alternative suggestions for how to accomplish what the SQL does (caveat is that it must run in the database and not be brought down the client for further computation).

È stato utile?

Soluzione

Something like:

Functions.IIF(ChildViewFields.Name.In("Required1", "Required2", "Required3"), 1, 0).Sum().NotEqual(3)

(so place that in the Having call)

Please next time post on our support forums so we can pick up the question right away as we dont monitor stackoverflow regularly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top