FieldCompareSetPredicate - Why does this generate two queries?

Posts   
 
    
jelacroix
User
Posts: 2
Joined: 28-Jun-2006
# Posted on: 03-Oct-2006 20:20:04   

IPredicateExpression filter = new PredicateExpression(ReqMastFields.QA_Date == DBNull.Value);
filter.AddWithAnd(ReqMastFields.Void == 0);
filter.AddWithAnd(ReqMastFields.VoidDate == DBNull.Value);
filter.AddWithAnd(ReqMastFields.VoidUser == DBNull.Value);

ReqMastCollection reqMastCollection = new ReqMastCollection();
IPredicateExpression groupFilter = new PredicateExpression(
    OnlineClientGroupFields.OnlineGroupInfoId== SessionData.UserToken.OnlineGroupInfoID);


filter.AddWithAnd(new FieldCompareSetPredicate(
        ReqMastFields.ClientId, OnlineClientGroupFields.ClientId, SetOperator.In, groupFilter));

return (int)reqMastCollection.GetScalar(ReqMastFieldIndex.Id, null, AggregateFunction.Count, filter);

Any idea why that would create two queries?

Query: SELECT [Bai].[dbo].[OnlineClientGroup].[ClientId] FROM [Bai].[dbo].[OnlineClientGroup] WHERE ( [Bai].[dbo].[OnlineClientGroup].[OnlineGroupInfoId] = @OnlineGroupInfoId2)

Parameter: @OnlineGroupInfoId2 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 16.

Query: SELECT TOP 1 COUNT([Bai].[dbo].[ReqMast].[Id]) AS [Id] FROM [Bai].[dbo].[ReqMast] WHERE ( [Bai].[dbo].[ReqMast].[QA_Date] IS NULL AND [Bai].[dbo].[ReqMast].[Void] = @Void1 AND [Bai].[dbo].[ReqMast].[VoidDate] IS NULL AND [Bai].[dbo].[ReqMast].[VoidUser] IS NULL AND [Bai].[dbo].[ReqMast].[ClientId] IN (SELECT [Bai].[dbo].[OnlineClientGroup].[ClientId] FROM [Bai].[dbo].[OnlineClientGroup] WHERE ( [Bai].[dbo].[OnlineClientGroup].[OnlineGroupInfoId] = @OnlineGroupInfoId2)))

Parameter: @Void1 : Boolean. Length: 0. Precision: 1. Scale: 0. Direction: Input. Value: 0. Parameter: @OnlineGroupInfoId2 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 16.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Oct-2006 21:33:21   

The first is the query generated which will be placed inside the other one as the subquery, so there's just 1 query executed.

Frans Bouma | Lead developer LLBLGen Pro
jelacroix
User
Posts: 2
Joined: 28-Jun-2006
# Posted on: 03-Oct-2006 22:19:59   

Ah. That kinda blows my mind. I always assumed everything that was displayed as debug info was executed. Is there a way to tell whats getting executed (without using sql profiler)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Oct-2006 22:51:54   

jelacroix wrote:

Ah. That kinda blows my mind. I always assumed everything that was displayed as debug info was executed. Is there a way to tell whats getting executed (without using sql profiler)?

Yes, (in v2.0 that is), set the ORMPersistenceExecution to 4, you'll then see the query executed simple_smile

Frans Bouma | Lead developer LLBLGen Pro