我需要使用 EF 创建 Linq lambda 语句。
我有4个固定表(不包括参考表),需要加入。但是需要检索的列名称是基于引用表中的列名称的。
如上图所示,DB_TABLE
列是需要连接表的列(请忽略.SHIPTO
和.CONSIGNEE
,仅需REL_BATCH_PARTY
)。
DB_FIELD
列是我需要选择的列。
示例
SUBSTR({0}CONTACT_PHONE,0,8)
所以我需要像SUBSTR(REL_BATCH_PARTY.CONTACT_PHONE,0,8)
。
{0}将替换为表名。
这是基于引用表的最终SQL语句:
SELECT *
FROM
(SELECT
(SELECT substr(REL_BATCH_PARTY.CONTACT_PHONE, 0, 8)
FROM REL_BATCH_PARTY
WHERE REL_BATCH_PARTY.REL_BATCH_ID = REL_BATCH.ID
AND REL_BATCH_PARTY.TYPE_CODE = 'SHIPTO') CONTACT_PHONE_SUBSTR,
(SELECT REL_BATCH_PARTY.CONTACT_PHONE
FROM REL_BATCH_PARTY
WHERE REL_BATCH_PARTY.REL_BATCH_ID = REL_BATCH.ID
AND REL_BATCH_PARTY.TYPE_CODE = 'SHIPTO') CONTACT_PHONE,
TO_CHAR(SYSDATE, 'dd-MM-yyyy') TODAY,
REL_BATCH.REL_NO,
(SELECT REL_BATCH_PARTY.ADDR01
FROM REL_BATCH_PARTY
WHERE REL_BATCH_PARTY.REL_BATCH_ID = REL_BATCH.ID
AND REL_BATCH_PARTY.TYPE_CODE = 'CONSIGNEE') ADDR01,
REL_BATCH_CONTAINER.CONTAINER_NO,
ROW_NUMBER() OVER(PARTITION BY REL_BATCH.ID
ORDER BY REL_BATCH_CONTAINER.ID, REL_BATCH_PARTY.TYPE_CODE) num
FROM REL_BATCH REL_BATCH
LEFT JOIN REL_BATCH_PARTY REL_BATCH_PARTY ON REL_BATCH.ID = REL_BATCH_PARTY.REL_BATCH_ID
LEFT JOIN REL_BATCH_CONTAINER REL_BATCH_CONTAINER ON REL_BATCH.ID = REL_BATCH_CONTAINER.REL_BATCH_ID WHERE ..... )A
WHERE A.NUM = 1
是否总有使用Linq Lambda表达式创建的内容?
DB_FIELD
列和行将根据参考表中的用户输入而动态变化。 DB_TABLE
仅使用这4个表(REL_BATCH
,REL_BATCH_PARTY
,REL_BATCH_ATTR
,REL_BATCH_CONTAINER
)。关系是ID
中的REL_BATCH
在所有其他3个表中都具有外键。
谢谢。