Hi!
We're using GetDbCount() in a validation procedure to verify a certain piece of data is unique in it's table (vehicle registration number, to be precise):
DataAccessAdapter adapter = new DataAccessAdapter();
IEntityFields2 fields = new EntityFields2(1);
fields.DefineField(BOHelper.CarFields.Registration, 0);
RelationPredicateBucket bucket = new RelationPredicateBucket((BOHelper.CarFields.Registration == _car.Registration) & (BOHelper.CarFields.Id != _car.Id));
int regCount = adapter.GetDbCount(fields, bucket);
While monitoring the trace output, we discovered that LLBL (v.2.5. Final) creates 2 SQL statements to retrieve this count:
[16:17:18]Method Enter: CreateRowCountDQ
[16:17:18]Method Enter: CreateSelectDQ
[16:17:18]Method Enter: CreateSelectDQ
[16:17:18]Generated Sql query:
Query: SELECT [Car].[Registration] FROM [Car] WHERE ( ( [Car].[Registration] = @Registration1 AND [Car].[ID] <> @Id2))
Parameter: @Registration1 : String. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "SB-345-AB".
Parameter: @Id2 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.
[16:17:18]Method Exit: CreateSelectDQ
[16:17:18]Generated Sql query:
Query: SELECT COUNT(*) AS NumberOfRows FROM (SELECT [Car].[Registration] FROM [Car] WHERE ( ( [Car].[Registration] = @Registration1 AND [Car].[ID] <> @Id2))) TmpResult
Parameter: @Registration1 : String. Length: 10. Precision: 0. Scale: 0. Direction: Input. Value: "SB-345-AB".
Parameter: @Id2 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.
[16:17:18]Method Exit: CreateRowCountDQ
Why is this so?