Я преобразовываю наш Уровень доступа к данным из Telerik ORM (устарел) в EF 6. Он подключается к источнику данных Oracle 12c с ограничением в 30 символов.Некоторые имена таблиц и имен столбцов содержат ровно 30 символов (как в этом примере ниже), некоторые короче.
Запросы Linq to Sql уже существуют и работают с Telerik, потому что он использовал псевдоним для имен столбцов как t1,t2 и т. д., тогда как EF, очевидно, копирует оригинальное имя столбца как псевдоним.В большинстве случаев это работает, за исключением объединений кодовой таблицы, где и PK кодовой таблицы, и FK родительской таблицы в точности совпадают, затем он добавляет 1 к концу столбца alais, таким образом делая его 31 символом.Как вы можете догадаться, Oracle жалуется.
Мне нужно найти способ заставить EF использовать более короткий псевдоним, любой способ сделать это?
Вот запрос Linq:
var dbElevationsHistory = (from elevationHist in dbContext.ElevationDataReadingJournals
join it in dbContext.MeasurementIssueTypes on elevationHist.MeasurementIssueTypeId equals it.MeasurementIssueTypeId into iType
from issueType in iType.DefaultIfEmpty()
join mt in dbContext.ElevationMeasureMethodTypes on elevationHist.ElevationMeasureMethodTypeId equals mt.ElevationMeasureMethodTypeId into mType
from methodType in mType.DefaultIfEmpty()
join at in dbContext.ElevationAccuracyTypes on elevationHist.ElevationAccuracyTypeId equals at.ElevationAccuracyTypeId into aType
from accuracyType in aType.DefaultIfEmpty()
join cAgency in dbContext.Organizations on elevationHist.CoopAgencyOrganizationId equals cAgency.OrganizationId into foundAgencies
from coopAgency in foundAgencies.DefaultIfEmpty()
where elevationHist.StationId == wellKey
select new { elevationHist, issueType, accuracyType, methodType, coopAgency })
.OrderByDescending(eh => eh.elevationHist.ModifiedDate)
.OrderByDescending(eh => eh.elevationHist.ElevationDataReadingJournalId);
И SQL-запрос, который он производит:
SELECT
"Project1"."C1" AS "C1",
"Project1"."EWM_ELEVATION_DATA_READ_JRL_ID" AS "EWM_ELEVATION_DATA_READ_JRL_ID",
"Project1"."EWM_ELEVATION_DATA_READING_ID" AS "EWM_ELEVATION_DATA_READING_ID",
"Project1"."CRUD_TYPE" AS "CRUD_TYPE",
"Project1"."CRUD_DT" AS "CRUD_DT",
"Project1"."MEASUREMENT_DT" AS "MEASUREMENT_DT",
"Project1"."ORG_ID" AS "ORG_ID",
"Project1"."EWM_MEASUREMENT_ISSUE_TYPE_ID" AS "EWM_MEASUREMENT_ISSUE_TYPE_ID",
"Project1"."EWM_STATION_ID" AS "EWM_STATION_ID",
"Project1"."EWM_ELEV_MEASURE_METHOD_TYP_ID" AS "EWM_ELEV_MEASURE_METHOD_TYP_ID",
"Project1"."EWM_ELEVATION_ACCURACY_TYPE_ID" AS "EWM_ELEVATION_ACCURACY_TYPE_ID",
"Project1"."REFERENCE_POINT_ELEVATION" AS "REFERENCE_POINT_ELEVATION",
"Project1"."GROUND_SURFACE_ELEVATION" AS "GROUND_SURFACE_ELEVATION",
"Project1"."WATER_SURFACE_READING" AS "WATER_SURFACE_READING",
"Project1"."REFERENCE_POINT_READING" AS "REFERENCE_POINT_READING",
"Project1"."MANDATORY_READING" AS "MANDATORY_READING",
"Project1"."COMMENTS" AS "COMMENTS",
"Project1"."MODIFIED_DATE" AS "MODIFIED_DATE",
"Project1"."MODIFIED_USER" AS "MODIFIED_USER",
"Project1"."MODIFIED_PROC" AS "MODIFIED_PROC",
"Project1"."COOPERATING_AGENCY_ORG_ID" AS "COOPERATING_AGENCY_ORG_ID",
"Project1"."APPL_ID" AS "APPL_ID",
"Project1"."SUBMISSION_DATE" AS "SUBMISSION_DATE",
"Project1"."EWM_MEASUREMENT_ISSUE_TYPE_ID1" AS "EWM_MEASUREMENT_ISSUE_TYPE_ID1",
"Project1"."EWM_MEASURE_ISSUE_TYPE_CODE" AS "EWM_MEASURE_ISSUE_TYPE_CODE",
"Project1"."EWM_MEASURE_ISSUE_TYPE_DESC" AS "EWM_MEASURE_ISSUE_TYPE_DESC",
"Project1"."EWM_MEASURE_ISSUE_TYPE_ACTV" AS "EWM_MEASURE_ISSUE_TYPE_ACTV",
"Project1"."EWM_MEASURE_ISSUE_TYPE_ORDER" AS "EWM_MEASURE_ISSUE_TYPE_ORDER",
"Project1"."EWM_MEASURE_ISSUE_TYPE_CLASS" AS "EWM_MEASURE_ISSUE_TYPE_CLASS",
"Project1"."MODIFIED_DATE1" AS "MODIFIED_DATE1",
"Project1"."MODIFIED_USER1" AS "MODIFIED_USER1",
"Project1"."MODIFIED_PROC1" AS "MODIFIED_PROC1",
"Project1"."APPL_ID1" AS "APPL_ID1",
"Project1"."EWM_ELEVATION_ACCURACY_TYPE_ID1" AS "EWM_ELEVATION_ACCURACY_TYPE_ID1",
"Project1"."EWM_ELEVATION_ACCURACY_DESC" AS "EWM_ELEVATION_ACCURACY_DESC",
"Project1"."EWM_ELEVATION_ACCURACY_ACTV" AS "EWM_ELEVATION_ACCURACY_ACTV",
"Project1"."EWM_ELEVATION_ACCURACY_ORDER" AS "EWM_ELEVATION_ACCURACY_ORDER",
"Project1"."MODIFIED_DATE3" AS "MODIFIED_DATE2",
"Project1"."MODIFIED_USER3" AS "MODIFIED_USER2",
"Project1"."MODIFIED_PROC3" AS "MODIFIED_PROC2",
"Project1"."EWM_ELEVATION_ACCURACY_CD" AS "EWM_ELEVATION_ACCURACY_CD",
"Project1"."APPL_ID3" AS "APPL_ID2",
"Project1"."EWM_ELEV_MEASURE_METHOD_TYP_ID1" AS "EWM_ELEV_MEASURE_METHOD_TYP_ID1",
"Project1"."EWM_ELEV_MEASURE_METHOD_DESC" AS "EWM_ELEV_MEASURE_METHOD_DESC",
"Project1"."EWM_ELEV_MEASURE_METHOD_ACTV" AS "EWM_ELEV_MEASURE_METHOD_ACTV",
"Project1"."EWM_ELEV_MEASURE_METHOD_ORDER" AS "EWM_ELEV_MEASURE_METHOD_ORDER",
"Project1"."MODIFIED_DATE2" AS "MODIFIED_DATE3",
"Project1"."MODIFIED_USER2" AS "MODIFIED_USER3",
"Project1"."MODIFIED_PROC2" AS "MODIFIED_PROC3",
"Project1"."EWM_ELEV_MEASURE_METHOD_CD" AS "EWM_ELEV_MEASURE_METHOD_CD",
"Project1"."APPL_ID2" AS "APPL_ID3",
"Project1"."ORG_ID1" AS "ORG_ID1",
"Project1"."ORG_NAME" AS "ORG_NAME",
"Project1"."ORG_ABBR" AS "ORG_ABBR",
"Project1"."ORG_TYPE_ID" AS "ORG_TYPE_ID",
"Project1"."MODIFIED_DATE4" AS "MODIFIED_DATE4",
"Project1"."MODIFIED_USER4" AS "MODIFIED_USER4",
"Project1"."MODIFIED_PROC4" AS "MODIFIED_PROC4",
"Project1"."ORG_TIN" AS "ORG_TIN"
FROM ( SELECT
"Extent1"."EWM_ELEVATION_DATA_READ_JRL_ID" AS "EWM_ELEVATION_DATA_READ_JRL_ID",
"Extent1"."EWM_ELEVATION_DATA_READING_ID" AS "EWM_ELEVATION_DATA_READING_ID",
"Extent1"."CRUD_TYPE" AS "CRUD_TYPE",
"Extent1"."CRUD_DT" AS "CRUD_DT",
"Extent1"."MEASUREMENT_DT" AS "MEASUREMENT_DT",
"Extent1"."ORG_ID" AS "ORG_ID",
"Extent1"."EWM_MEASUREMENT_ISSUE_TYPE_ID" AS "EWM_MEASUREMENT_ISSUE_TYPE_ID",
"Extent1"."EWM_STATION_ID" AS "EWM_STATION_ID",
"Extent1"."EWM_ELEV_MEASURE_METHOD_TYP_ID" AS "EWM_ELEV_MEASURE_METHOD_TYP_ID",
"Extent1"."EWM_ELEVATION_ACCURACY_TYPE_ID" AS "EWM_ELEVATION_ACCURACY_TYPE_ID",
"Extent1"."REFERENCE_POINT_ELEVATION" AS "REFERENCE_POINT_ELEVATION",
"Extent1"."GROUND_SURFACE_ELEVATION" AS "GROUND_SURFACE_ELEVATION",
"Extent1"."WATER_SURFACE_READING" AS "WATER_SURFACE_READING",
"Extent1"."REFERENCE_POINT_READING" AS "REFERENCE_POINT_READING",
"Extent1"."MANDATORY_READING" AS "MANDATORY_READING",
"Extent1"."COMMENTS" AS "COMMENTS",
"Extent1"."MODIFIED_DATE" AS "MODIFIED_DATE",
"Extent1"."MODIFIED_USER" AS "MODIFIED_USER",
"Extent1"."MODIFIED_PROC" AS "MODIFIED_PROC",
"Extent1"."COOPERATING_AGENCY_ORG_ID" AS "COOPERATING_AGENCY_ORG_ID",
"Extent1"."APPL_ID" AS "APPL_ID",
"Extent1"."SUBMISSION_DATE" AS "SUBMISSION_DATE",
1 AS "C1",
"Extent2"."EWM_MEASUREMENT_ISSUE_TYPE_ID" AS "EWM_MEASUREMENT_ISSUE_TYPE_ID1",
"Extent2"."EWM_MEASURE_ISSUE_TYPE_CODE" AS "EWM_MEASURE_ISSUE_TYPE_CODE",
"Extent2"."EWM_MEASURE_ISSUE_TYPE_DESC" AS "EWM_MEASURE_ISSUE_TYPE_DESC",
"Extent2"."EWM_MEASURE_ISSUE_TYPE_ACTV" AS "EWM_MEASURE_ISSUE_TYPE_ACTV",
"Extent2"."EWM_MEASURE_ISSUE_TYPE_ORDER" AS "EWM_MEASURE_ISSUE_TYPE_ORDER",
"Extent2"."EWM_MEASURE_ISSUE_TYPE_CLASS" AS "EWM_MEASURE_ISSUE_TYPE_CLASS",
"Extent2"."MODIFIED_DATE" AS "MODIFIED_DATE1",
"Extent2"."MODIFIED_USER" AS "MODIFIED_USER1",
"Extent2"."MODIFIED_PROC" AS "MODIFIED_PROC1",
"Extent2"."APPL_ID" AS "APPL_ID1",
"Extent3"."EWM_ELEV_MEASURE_METHOD_TYP_ID" AS "EWM_ELEV_MEASURE_METHOD_TYP_ID1",
"Extent3"."EWM_ELEV_MEASURE_METHOD_DESC" AS "EWM_ELEV_MEASURE_METHOD_DESC",
"Extent3"."EWM_ELEV_MEASURE_METHOD_ACTV" AS "EWM_ELEV_MEASURE_METHOD_ACTV",
"Extent3"."EWM_ELEV_MEASURE_METHOD_ORDER" AS "EWM_ELEV_MEASURE_METHOD_ORDER",
"Extent3"."MODIFIED_DATE" AS "MODIFIED_DATE2",
"Extent3"."MODIFIED_USER" AS "MODIFIED_USER2",
"Extent3"."MODIFIED_PROC" AS "MODIFIED_PROC2",
"Extent3"."EWM_ELEV_MEASURE_METHOD_CD" AS "EWM_ELEV_MEASURE_METHOD_CD",
"Extent3"."APPL_ID" AS "APPL_ID2",
**"Extent4"."EWM_ELEVATION_ACCURACY_TYPE_ID" AS "EWM_ELEVATION_ACCURACY_TYPE_ID1"**,
"Extent4"."EWM_ELEVATION_ACCURACY_DESC" AS "EWM_ELEVATION_ACCURACY_DESC",
"Extent4"."EWM_ELEVATION_ACCURACY_ACTV" AS "EWM_ELEVATION_ACCURACY_ACTV",
"Extent4"."EWM_ELEVATION_ACCURACY_ORDER" AS "EWM_ELEVATION_ACCURACY_ORDER",
"Extent4"."MODIFIED_DATE" AS "MODIFIED_DATE3",
"Extent4"."MODIFIED_USER" AS "MODIFIED_USER3",
"Extent4"."MODIFIED_PROC" AS "MODIFIED_PROC3",
"Extent4"."EWM_ELEVATION_ACCURACY_CD" AS "EWM_ELEVATION_ACCURACY_CD",
"Extent4"."APPL_ID" AS "APPL_ID3",
"Extent5"."ORG_ID" AS "ORG_ID1",
"Extent5"."ORG_NAME" AS "ORG_NAME",
"Extent5"."ORG_ABBR" AS "ORG_ABBR",
"Extent5"."ORG_TYPE_ID" AS "ORG_TYPE_ID",
"Extent5"."MODIFIED_DATE" AS "MODIFIED_DATE4",
"Extent5"."MODIFIED_USER" AS "MODIFIED_USER4",
"Extent5"."MODIFIED_PROC" AS "MODIFIED_PROC4",
"Extent5"."ORG_TIN" AS "ORG_TIN"
FROM "EWM_ADM"."EWM_ELEVATION_DATA_READING_JRL" "Extent1"
LEFT OUTER JOIN "EWM_ADM"."EWM_MEASUREMENT_ISSUE_TYPE" "Extent2" ON "Extent1"."EWM_MEASUREMENT_ISSUE_TYPE_ID" = "Extent2"."EWM_MEASUREMENT_ISSUE_TYPE_ID"
LEFT OUTER JOIN "EWM_ADM"."EWM_ELEV_MEASURE_METHOD_TYP" "Extent3" ON "Extent1"."EWM_ELEV_MEASURE_METHOD_TYP_ID" = "Extent3"."EWM_ELEV_MEASURE_METHOD_TYP_ID"
LEFT OUTER JOIN "EWM_ADM"."EWM_ELEVATION_ACCURACY_TYPE" "Extent4" ON "Extent1"."EWM_ELEVATION_ACCURACY_TYPE_ID" = "Extent4"."EWM_ELEVATION_ACCURACY_TYPE_ID"
LEFT OUTER JOIN "BUS_ADM"."ORGANIZATION" "Extent5" ON "Extent1"."COOPERATING_AGENCY_ORG_ID" = "Extent5"."ORG_ID"
WHERE (("Extent1"."EWM_STATION_ID" = 52370) OR (("Extent1"."EWM_STATION_ID" IS NULL) AND (52370 IS NULL)))
) "Project1"
ORDER BY "Project1"."EWM_ELEVATION_DATA_READ_JRL_ID" DESC
Эта строка, о которой идет речь, помечена звездочкой в запросе, поскольку я не могу выделить ее жирным шрифтом).
"Extent4"."EWM_ELEVATION_ACCURACY_TYPE_ID" AS "EWM_ELEVATION_ACCURACY_TYPE_ID1"
Как вы можете видеть, это добавило 1 к псевдониму.Мне нужно предотвратить это или принудительно настроить псевдоним.