0

我剛剛開始使用反向工程師代碼優先,並且遇到阻止程序,我無法找到答案。反向工程師代碼優先 - 沒有現有的數據庫關係

我映射了三個沒有在數據庫端建立任何關係的表。

  • 錯誤 - 列ErrorID中,ErrorName等。
  • 用戶 - 列是用戶名,用戶名等...
  • ErrorUsers - 列ErrorUsersID,ErrorID中,用戶名

這個想法是,一個錯誤可以讓一個或多個用戶負責。我希望能夠運行查詢,它將返回所有相應用戶的所有錯誤。

爲了我的錯誤類,我添加了一個名爲屬性:

public virtual ErrorUser ErrorUsers { get; set; } 

要我ErrorMap.cs,我已經加入

this.HasRequired(e => e.ErrorUsers) 
       .WithMany() 
       .HasForeignKey(e => e.ErrorID); 

然而,當我跑我的查詢返回的所有錯誤與所有相應的用戶,我收到以下錯誤:

System.Data.Entity.ModelConfiguration.ModelValidationException was unhandled by user code 
    Message=One or more validation errors were detected during model generation: 

    System.Data.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'Error_ErrorUsers_Source' in relationship 'Error_ErrorUsers'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be ?1?. 

    Source=EntityFramework 

我一直在尋求答案爲l幾個小時,我可以找到的唯一代碼示例是那些使用visual.edmx樣式,我試圖避免。

有人可以幫我嗎?

回答

0

我放棄了這個,我用鑰匙重新創建了表格並重新導入了所有內容

相關問題