2014-02-26 39 views
1

我有這個錯誤,它的竊聽我的地獄已經失去了一天試圖找出它可以有人幫助我請我相信這是與我做的外鍵,但不能弄清楚什麼是錯的。無法理解這與實體框架

概念模型類型'socialprofilesModel.FK_Logins_Users'中的Member'Users'在CLR類型'socialprofilesModel.FK_Logins_Users1'中不存在。

說明:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。

Exception Details: System.Data.MappingException: The Member 'Users' in the conceptual model type 'socialprofilesModel.FK_Logins_Users' is not present in the CLR type 'socialprofilesModel.FK_Logins_Users1'. 

源錯誤:

Line 22: 
Line 23:    List<SPLogin> validUser; 
Line 24:    validUser = socialProfileContext.ValidateUser(txtuserName.Text, txtPassword.Text); 
Line 25:    if (validUser !=null) 
Line 26:     { 

Source File: c:\Users\dave\Documents\Visual Studio 2012\WebSites\cmsforletsmakeapps\admin\Login.aspx.cs Line: 24 

堆棧跟蹤:

[MappingException: The Member 'Users' in the conceptual model type 'socialprofilesModel.FK_Logins_Users' is not present in the CLR type 'socialprofilesModel.FK_Logins_Users1'.] 
    System.Data.Mapping.DefaultObjectMappingItemCollection.GetObjectMember(EdmMember edmMember, StructuralType objectType) +8321746 
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadAssociationTypeMapping(ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings) +169 
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping(EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings) +234 
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadTypeMapping(EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings) +100 
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadEntityTypeOrComplexTypeMapping(ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings) +445 
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping(EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary`2 typeMappings) +175 
    System.Data.Mapping.DefaultObjectMappingItemCollection.LoadObjectMapping(EdmType cdmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection) +82 
    System.Data.Mapping.DefaultObjectMappingItemCollection.TryGetMap(String identity, DataSpace typeSpace, Boolean ignoreCase, Map& map) +333 
    System.Data.Metadata.Edm.ClrPerspective.TryGetTypeByName(String fullName, Boolean ignoreCase, TypeUsage& typeUsage) +91 
    System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType) +111 
    System.Data.Objects.ObjectContext.GetEntitySetForNameAndType(String entitySetName, Type entityCLRType, String exceptionParameterName) +30 
    System.Data.Objects.ObjectContext.CreateObjectSet(String entitySetName) +60 
    SPDataContext.socialprofilesEntities.get_SPLogins() +102 
    SPDataContext.EntityFramework.MyContext.ValidateUser(String username, String password) +165 

[EntityContextException: ValidateUser failed.] 
    SPDataContext.EntityFramework.MyContext.ValidateUser(String username, String password) +1442 
    admin_Login.btnlogin_Click(Object sender, EventArgs e) in c:\Users\dave\Documents\Visual Studio 2012\WebSites\cmsforletsmakeapps\admin\Login.aspx.cs:24 
    Telerik.Web.UI.RadButton.OnClick(ButtonClickEventArgs e) +134 
    Telerik.Web.UI.RadButton.RaisePostBackEvent(String eventArgument) +284 
    Telerik.Web.UI.RadButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +42 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9703558 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724 

DB編輯請找我的EDMX文件請注意,我只引擎收錄它引起的長度將超過什麼允許是張貼所以請原諒我,如果不正確的方式。

http://pastebin.com/hZU8zmRu

+0

你能分享你的用戶模型的來源嗎? –

+0

@MichaelDunlap在棧上做這件事的最好方法是什麼 – rogue39nin

+0

如果你使用EF Code-First,你可以分享你的模型的源代碼。如果你使用其他的東西,你仍然需要分享'socialprofilesModel'與代碼相關的'Users'的關係。 –

回答

1

我對這個問題完全沒有解決辦法,但我幾件事情你可以檢查和測試:

  • 你EDMX文件版本3:

    <edmx:Edmx Version="3.0" ...> 
    

    從我自己的項目我可以看到版本3在.NET 4.5中使用(而不是使用EDMX版本2的.NET 4.0)。此外,該文件中出現的UseStrongSpatialTypes屬性指示該文件適用於.NET 4.5。或者您是否下載並使用EF 6 Nuget包? EF 6甚至可以在.NET 4.0下支持版本3,但我不確定。

  • 您的異常消息中的搜索字符串FK_Logins_UsersFK_Logins_Users1都不能在整個EDMX文件中找到。 (但是在名稱中有一個FK_SPLogins_Users以及附加的「SP」)。您是否粘貼了正好是的例外消息?如果是,則表示嵌入在生產/測試系統中發生錯誤的組件中的EDMX不是您在問題中粘貼的EDMX。 EDMX是否可能被更改,但應用程序未重新編譯/重新部署?

  • 概念模型部分無法包含「成員」Users(作爲例外聲明),但名稱爲User的成員。你有沒有在某個時候打開或關閉名稱複數化?無論如何,它再次表明您的問題中的EDMX與部署的EDMX不同。在您的EDMX

  • 代碼生成策略是Default

    <DesignerProperty Name="CodeGenerationStrategy" Value="Default" /> 
    

    這意味着你應該有下VS解決方案資源管理您的EDMX文件XXX.Designer.cs文件(打開從EDMX文件留下的+節點)。該文件包含從EntityObject派生的實體生成的代碼(=「CLR類型」,例外情況正在討論)。也許這個文件並不是最新的EDMX文件,除非代碼生成在模型更改後沒有自動運行,或者手動更改了手動代碼文件或手動更改了XML編輯器中的EDMX文件,否則不應該發生。在解決方案資源管理器中右鍵單擊edmx文件以強制生成代碼時,可以嘗試使用「運行自定義工具」(或類似工具)。

所有的一切問題非常模樣的部署EDMX和部署的代碼不匹配,你應該在VS仔細一定檢查與您的版本部署版本或重新運行自定義代碼生成工具,並重新編譯和重新部署應用程序。