2012-11-06 42 views
1

所以。實體框架不生成關聯屬性

我無法解決這個小問題。

我有幾個班,它都很好,很好。直到現在。我現在添加了另一個類(MatchResult),它可以工作。 Before

但是當我嘗試做正確的關聯關係:

enter image description here

它失敗,出現運行時異常。

錯誤:

Schema specified is not valid. Errors:

The relationship 'DbModel.FK_ProductPrice' was not loaded because the type 'DbModel.Product' is not available.

The following information may be useful in resolving the previous error:

The required property 'MatchResults' does not exist on the type 'PriceMonitor.Model.Product'.

The relationship 'DbModel.FK_WebshopProduct' was not loaded because the type 'DbModel.Product' is not available.

The following information may be useful in resolving the previous error:

The required property 'MatchResults' does not exist on the type 'PriceMonitor.Model.Product'.

看來 - 因某種原因 - 即EF不會產生對產品類中的MatchResults屬性。

這種方法適用於我曾經使用EF製作過的每一個班級。到現在爲止。

+1

您是否檢查過該屬性實際上是在代碼中生成的。你可以嘗試強制生成代碼嗎? – Pawel

+0

如何強制重新生成代碼? –

+0

沒關係,我找到了答案:-) –

回答

0

我找到了答案。顯然,這是實體框架中已確認的錯誤。 (什麼?!)

看來,如果將.emdx文件放在子文件夾中,自動代碼生成將不起作用。

參見this question

+0

是的,這是VS2012中的一個已知錯誤 - 這就是爲什麼我要求強制代碼生成... – Pawel

0

我剛剛發生了同樣的錯誤,我的csdl,ssdl和msl的名稱與我的edmx的名稱不同,並且包含我的解決方案中的其他edmx的名稱。我改變了連接字符串並修復了它。

0

使用EF Database First並且生成的POCO類未與edmx文件保持同步時會發生這種情況,例如,當POCO類與edmx不在同一個項目中時。