Joining the same persistent twice exposes the same name twice in the generated sql query.
var query = from relat in Repository.GetPersistents<RelatieEntity>()
join b in Repository.GetPersistents<RelatieAdresEntity>()
on relat.RelatieRegNumm equals b.RelatieRegNumm
into temp_bezoekadres
join p in Repository.GetPersistents<RelatieAdresEntity>()
on relat.RelatieRegNumm equals p.RelatieRegNumm
into temp_postadres
from bezoekadres in temp_bezoekadres.DefaultIfEmpty()
from postadres in temp_postadres.DefaultIfEmpty()
where relat.Naam.Contains(naam)
where bezoekadres.AandTypeAdres == 1
where postadres.AandTypeAdres == 2
select new
{
relat.RelatieRegNumm,
relat.Naam,
relat.RelatieKenmerk,
BezoekadresStraat = bezoekadres.Straat,
BezoekadresHuisNummer = bezoekadres.HuisNummer,
BezoekadresPlaats = bezoekadres.Plaats,
BezoekadresPostcode = bezoekadres.Postcode,
PostadresStraat = postadres.Straat,
PostadresHuisNummer = postadres.HuisNummer,
PostadresPlaats = postadres.Plaats,
PostadresPostcode = postadres.Postcode
};
var queryResult = query.GetObjectReader();
Generated query:
SELECT "RELAT"."RELATIE_REG_NUMM" as RelatieRegNumm, "RELAT"."NAAM" as Naam, "RELAT"."RELATIE_KENMERK" as RelatieKenmerk, "RADRS"."STRAAT" as BezoekadresStraat, "RADRS"."HUIS_NUMMER" as BezoekadresHuisNummer, "RADRS"."PLAATS" as BezoekadresPlaats, "RADRS"."POSTCODE" as BezoekadresPostcode, "RADRS"."STRAAT" as PostadresStraat, "RADRS"."HUIS_NUMMER" as PostadresHuisNummer, "RADRS"."PLAATS" as PostadresPlaats, "RADRS"."POSTCODE" as PostadresPostcode FROM "RELAT" LEFT OUTER JOIN "RADRS" ON "RELAT"."RELATIE_REG_NUMM" = "RADRS"."RELATIE_REG_NUMM" LEFT OUTER JOIN "RADRS" ON "RELAT"."RELATIE_REG_NUMM" = "RADRS"."RELATIE_REG_NUMM" WHERE "RELAT"."NAAM" like ? and ("RADRS"."AAND_TYPE_ADRES" = ?) and ("RADRS"."AAND_TYPE_ADRES" = ?)
Result:
{Chili.Opf3.Storages.StorageException: Pervasive.Data.SqlClient.Lna.LnaException: [LNA][Pervasive][ODBC Engine Interface]Tables or functions 'RADRS' and 'RADRS' have the same exposed names. Use correlation names to distinguish them. ---> Pervasive.Data.SqlClient.PsqlException: Pervasive.Data.SqlClient.Lna.LnaException: [LNA][Pervasive][ODBC Engine Interface]Tables or functions 'RADRS' and 'RADRS' have the same exposed names. Use correlation names to distinguish them.