dotnetdevcsharp
dotnetdevcsharp

Reputation: 3980

Cant Figure Out this with Entity Framework

I have this error and its bugging the hell out of me been lost for a day trying to figure it out can someone help me please i do believe it is something to do with me foreign keys but cant figure out whats wrong.

The Member 'Users' in the conceptual model type 'socialprofilesModel.FK_Logins_Users' is not present in the CLR type 'socialprofilesModel.FK_Logins_Users1'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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'.

Source Error:

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 

Stack Trace:

[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 Edit Please find my edmx file please note I only pastebin it cause the length would exceed whats is allowed to be posted so please forgive me if not correct way.

http://pastebin.com/hZU8zmRu

Upvotes: 1

Views: 583

Answers (1)

Slauma
Slauma

Reputation: 177133

I have absolutely no solution for the problem but I few things you could check and test:

  • Your EDMX file is version 3:

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

    From my own projects I can see that version 3 is used in .NET 4.5 (and not .NET 4.0 which uses version 2 for the EDMX). Also the UseStrongSpatialTypes attribute that occurs in the file indicates that this file is for .NET 4.5. Or did you download and use the EF 6 Nuget package? It might be possible that EF 6 supports version 3 even under .NET 4.0, but I'm not sure.

  • Neither the search string FK_Logins_Users nor FK_Logins_Users1 from your exception message can be found in the whole EDMX file. (However there is a FK_SPLogins_Users with the additional "SP" in the name.) Did you paste in the exception message exactly? If yes, it indicates that the EDMX that is embedded in the assembly on your production/test system where the error occurs is not the one you pasted in your question. Is it possible that the EDMX has been changed but the application not recompiled/redeployed?

  • The conceptual model section does nowhere contain a "member" Users (as the exception claims) but members with name User. Did you perhaps turn on or off name pluralization at some point? Anyway, it indicates again that the EDMX in your question is not identical with the deployed EDMX.

  • Code generation strategy in your EDMX is Default:

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

    That means you should have a XXX.Designer.cs file under your EDMX file in VS solution explorer (open the + node left from the EDMX file). That file contains the generated code (= the "CLR types" the exception is talking about) with the entities derived from EntityObject. Perhaps this file is not up to date with the EDMX file which shouldn't happen unless the code generation didn't run automatically for some reason after a model change or you changed the code file manually or EDMX file in an xml editor manually. You can try to use "Run custom tool" (or similar) when you right click on the edmx file in solution explorer to force the code generation.

All in all the problem very much looks like a mismatch of deployed EDMX and deployed code and you should definitely check the deployed version with the your version in VS carefully or re-run custom code generation tool and recompile and redeploy the application.

Upvotes: 1

Related Questions