我用我分貝第一,並有特定關聯,它總是返回空值,使用:實體框架包括表空
var results = _ABPRepository.Query(x => x.ABPArrangementId == arrangementId)
.Include(x => x.tb_ARRArrangement)
.Include(x => x.tb_ARRArrangement.Supplier)
.Include(x => x.tb_ARRArrangement.Supplier.tb_SCNSicCodesNew)
.Include(x => x.tb_BBRBatteryBackBrands)
.Include(x => x.tb_ARRArrangement.Supplier.Country)
.Include(x => x.tb_ARRArrangement.Supplier.InvoiceCountry)
.Include(x => x.Country)
.Select().FirstOrDefault();
下面總是空:
x.tb_ARRArrangement.Supplier.tb_SCNSicCodesNew
我已經驗證該SQL是正確的(下面簡要):
SELECT
/* ... */
[Project1].[SCN_SIC_Code] AS [SCN_SIC_Code],
[Project1].[SCN_SIC_Description] AS [SCN_SIC_Description]
/* ... */
FROM (SELECT
/* ... */
[Extent4].[SCN_SIC_Code] AS [SCN_SIC_Code],
[Extent4].[SCN_SIC_Description] AS [SCN_SIC_Description],
/* ... */
CASE WHEN ([Extent8].[BBRIDNumber] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
FROM [dbo].[tb_ABPArrangementBatteryBackProducer] AS [Extent1]
INNER JOIN [dbo].[tb_ARRArrangement] AS [Extent2] ON [Extent1].[ABPArrangementId] = [Extent2].[ARRIDNumber]
LEFT OUTER JOIN [dbo].[tb_SUPSupplier] AS [Extent3] ON [Extent2].[ARRSupplierId] = [Extent3].[SUPKey]
LEFT OUTER JOIN (SELECT
[tb_SCNSicCodesNew].[SCN_SIC_Code] AS [SCN_SIC_Code],
[tb_SCNSicCodesNew].[SCN_SIC_Description] AS [SCN_SIC_Description]
FROM [dbo].[tb_SCNSicCodesNew] AS [tb_SCNSicCodesNew]) AS [Extent4] ON [Extent3].[SUPEaHwrSicCode2007] = [Extent4].[SCN_SIC_Code]
LEFT OUTER JOIN [dbo].[tb_COUCountry] AS [Extent5] ON [Extent3].[SUPCountry] = [Extent5].[COUIDNumber]
LEFT OUTER JOIN [dbo].[tb_COUCountry] AS [Extent6] ON [Extent3].[SUPInvoiceCountry] = [Extent6].[COUIDNumber]
INNER JOIN [dbo].[tb_COUCountry] AS [Extent7] ON [Extent1].[ABPCorrespondanceCountry] = [Extent7].[COUIDNumber]
LEFT OUTER JOIN [dbo].[tb_BBRBatteryBackBrands] AS [Extent8] ON [Extent1].[ABPArrangementId] = [Extent8].[BBRABPIDNumber]
WHERE [Extent1].[ABPArrangementId] = 123456
) AS [Project1]
返回的記錄包含了我所期望的數據,但它不能映射到t他 results.tb_ARRArrangement.Supplier.tb_SCNSicCodesNew
財產。
所有其他包括按預期工作。
我已經試過:
閱讀有關地方包括可能無法正常工作(分組等),但他們似乎 不適用於我的方案爲包括不會被忽略, 更多的映射似乎失敗。
卸下從EDMX和所述關聯和表重新添加
重命名,並重新使關聯和導航屬性
清潔和重新構建
有不是表格之間的數據庫中的外鍵,但其他人也沒有,因此我沒有任何問題。
要檢查的東西的任何指針?
如何爲[ABPArrangementId:
然後,這是通過將低於在同一項目作爲上下文初始化:從上面的鏈接的代碼中加入一個攔截器修剪字符串修復該問題]在你的模式int或varchar中定義? – DaniDev
@DaniDev這是一個int – SWa
Gottcha!它似乎基於linq引擎如何解析它。只是想確定。不幸的是,我沒有答案。 – DaniDev