我有一個用於查詢兩個不同數據庫的EDMX(實體框架6.1.3)。數據庫之間有一些細微差別,但我只想要公共列。我從數據庫A生成了EDMX,並從圖中刪除了不在數據庫B中的列並重新生成了代碼。EF 6查詢包含未映射的列,打破查詢
如果我查詢數據庫B查詢包含我刪除的列,雖然最後的SELECT沒有。這意味着查詢失敗。
表映射顯示列,但什麼也沒有對價值/物業方:
唯一的例外是:
System.Data.Entity.Core.EntityCommandExecutionException : An error occurred while executing the command definition. See the inner exception for details.
----> System.Data.SqlClient.SqlException : Invalid column name 'ValidFromDate'.
Invalid column name 'ValidToDate'.
Invalid column name 'LastPulled'.
Invalid column name 'IsCurrent'.
的查詢被髮送到服務器是:
SELECT TOP (1)
[c].[FirstName] AS [FirstName],
[c].[LastName] AS [LastName],
[c].[HomePhone] AS [HomePhone],
[c].[WorkPhone] AS [WorkPhone],
[c].[MobilePhone] AS [MobilePhone],
[c].[Email] AS [Email],
[c].[Fax] AS [Fax]
FROM (SELECT
[Person].[FirstName] AS [FirstName],
[Person].[LastName] AS [LastName],
[Person].[HomePhone] AS [HomePhone],
[Person].[WorkPhone] AS [WorkPhone],
[Person].[MobilePhone] AS [MobilePhone],
[Person].[Email] AS [Email],
[Person].[Fax] AS [Fax],
[Person].[ValidFromDate] AS [ValidFromDate],
[Person].[ValidToDate] AS [ValidToDate],
[Person].[LastPulled] AS [LastPulled],
[Person].[IsCurrent] AS [IsCurrent]
FROM [dbo].[Person] AS [Person]) AS [c]
正如你所看到的那樣一個包含附加列的內部查詢。
在這一點上,我有點難以理解爲什麼會發生這種情況。如何從映射的兩側刪除這些列,或以其他方式阻止EF將不需要的列放入查詢的任何部分?
有趣 - 我在EDMX中包含視圖時看到了這些,我不記得在桌面定義上有一個視圖。很棒的發現 - 很高興你能解決你的問題! – Borophyll