Queryspec vs linq for In filtering

Posts   
 
    
JonE
User
Posts: 164
Joined: 15-Nov-2016
# Posted on: 06-Dec-2016 20:39:52   

Hi All,

I have a set of clients in a table and a set of userid/clientids in another table. I am looking to get the list of clients for a given user ID.

Plainly I can do this using both linq and queryspec. Is there a best way for this type of query? One reason that I am leaning towards queryspec as it seems to me that it would be easy to set up a reusable predicate filter for the in component.

Select clients from client where client in (select client from clientuserlink where user = x)

Regards

Jon

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-Dec-2016 00:30:25   

Please check Correlated Queries

JonE
User
Posts: 164
Joined: 15-Nov-2016
# Posted on: 07-Dec-2016 08:40:17   

Hi Walaa

Thanks for that - I hadn't seen that page before now.

I suppose that if all methods have the same SQL generated then it will be whichever is the best approach for me. Is that correct? If so then I can stop worrying that I am picking the right one and just pick one simple_smile Thats the problem with choices!

Best Regards

Jon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Dec-2016 09:52:46   

they generate the same SQL in most cases, as they transform to the same FieldCompareSetPredicate. The issue with linq is that it doesn't map 1:1 to SQL so there might be a slight difference sometimes, but in either case they will result in a query which results in the same resultset.

Frans Bouma | Lead developer LLBLGen Pro
JonE
User
Posts: 164
Joined: 15-Nov-2016
# Posted on: 07-Dec-2016 10:03:08   

OK fair enough I'll remember that.

Would I be right in assuming that when using queryspec if I am creating the data for a drop down that has 3 relevant fields I would be better off using the entity object instead of the DTO as the SQL generated will then just be for the table rather than any associated tables.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Dec-2016 10:53:01   

if all 3 fields are from the same entity and the dto has fields / nested dtos from other entities, then yes you avoid a join / nested query with fetching from the entity directly.

Frans Bouma | Lead developer LLBLGen Pro
JonE
User
Posts: 164
Joined: 15-Nov-2016
# Posted on: 07-Dec-2016 11:05:21   

Yeah thats right, in 9/10 cases they will be from the same entity. Thanks for the help simple_smile