New information. I use simple table for better understanding internal processes:
using System;
using System.Diagnostics;
using Model.DatabaseSpecific;
using Model.EntityClasses;
using Model.FactoryClasses;
using Model.HelperClasses;
namespace LLBLGenExperiment
{
internal class LlblGenExperiment
{
private static void Main(string[] args)
{
using (var adapter = new DataAccessAdapter())
{
var userEntities = new EntityCollection<UserEntity>(new UserEntityFactory());
Trace.WriteLine("FetchEntityCollection");
adapter.FetchEntityCollection(userEntities, null);
Trace.WriteLine("Fetched " + userEntities.Count + " entities.");
}
}
}
}
result:
FetchEntityCollection
'LLBLGenExperiment.vshost.exe' (Managed): Loaded 'D:\Work\Projects\Glavsnab.Ring.Realty\src\Enterprise\Tools\LLBLGenExperiment\bin\x86\Debug\SD.LLBLGen.Pro.DQE.Oracle10g.NET20.dll'
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query:
Query: SELECT "ACCOUNT"."ACCOUNT_ID" AS "Id", "ACCOUNT"."LAST_NAME" AS "LastName", "ACCOUNT"."EMAIL" AS "Email", "ACCOUNT"."ACTIVATED" AS "Activated", "ACCOUNT"."PASSWORD_HASH" AS "PasswordHash", "ACCOUNT"."PASSWORD_SALT" AS "PasswordSalt", "ACCOUNT"."DATE_CREATE" AS "DateCreate", "ACCOUNT"."DATE_LAST_LOGON" AS "DateLastLogOn", "ACCOUNT"."DATE_LAST_ACTIVITY" AS "DateLastActivity", "ACCOUNT"."DATE_LAST_PASSWORD_CHANGE" AS "DateLastPasswordChange", "ACCOUNT"."REGISTRATION_GUID" AS "RegistrationGuid", "ACCOUNT"."DATE_REGISTRATION" AS "DateRegistration", "ACCOUNT"."PHONE" AS "Phone", "ACCOUNT"."IS_DELETED" AS "IsDeleted", "ACCOUNT"."FIRM_ID" AS "FirmId", "ACCOUNT"."FIRST_NAME" AS "FirstName" FROM "ACCOUNT"
Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
'LLBLGenExperiment.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'LLBLGenExperiment.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Design\2.0.0.0__b03f5f7f11d50a3a\System.Design.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Fetched 158 entities.
All look fine, BUT when I add paging (thrid parameter in FetchEntityCollection method):
adapter.FetchEntityCollection(userEntities, null, 20);
then result is:
FetchEntityCollection
...
Query: SELECT * FROM (SELECT DISTINCT "ACCOUNT"."ACCOUNT_ID" AS "Id", "ACCOUNT"."LAST_NAME" AS "LastName", "ACCOUNT"."EMAIL" AS "Email", "ACCOUNT"."ACTIVATED" AS "Activated", "ACCOUNT"."PASSWORD_HASH" AS "PasswordHash", "ACCOUNT"."PASSWORD_SALT" AS "PasswordSalt", "ACCOUNT"."DATE_CREATE" AS "DateCreate", "ACCOUNT"."DATE_LAST_LOGON" AS "DateLastLogOn", "ACCOUNT"."DATE_LAST_ACTIVITY" AS "DateLastActivity", "ACCOUNT"."DATE_LAST_PASSWORD_CHANGE" AS "DateLastPasswordChange", "ACCOUNT"."REGISTRATION_GUID" AS "RegistrationGuid", "ACCOUNT"."DATE_REGISTRATION" AS "DateRegistration", "ACCOUNT"."PHONE" AS "Phone", "ACCOUNT"."IS_DELETED" AS "IsDeleted", "ACCOUNT"."FIRM_ID" AS "FirmId", "ACCOUNT"."FIRST_NAME" AS "FirstName" FROM "ACCOUNT") WHERE rownum <= 20
...
Fetched 20 entities.
We can see that DISTINCT keyword ! They ALWAYS appear when we using paging.
For simple tables
SELECT * FROM T1 fully equal SELECT DISTINCT * FROM T1, hovewer for JOINED tables like out VIEW (with left join) adding DISTINCT keyword after SELECT bring to catastrophic increase execution time