This project is read-only.

Retrieving Entity when Associative Table is Empty

Mar 6, 2011 at 10:07 PM

I have three tables, which collectively define a many-to-many associative table relationship:

MemberInfo -> MemberInfoRole <- RoleInfo

This is supports a simple MembershipProvider/RoleProvider web app where each member can have multiple roles.

When I do a LINQ expression against an empty MemberInfo table:

MyEntityContext context = new MyEntityContext()

MemberInfo curMI = (from m in context.MemberInfo select m).SingleOrDefault();

I get an error about a problem with retrieving an invalid relationship on the MemberInfoRole table (I'm doing this from memory).

Do I need to do something special to handle situations where the MemberInfo entity has not associative entry in the MemberInfoRole table?

- Mark 

Mar 7, 2011 at 7:30 PM

When I turn off the associated table feature, the problem goes away. This sounds to me like one of the requirements of an associated table relationship is that the "other side" of the relation (RoleInfo, in my example) can't be empty. But I'm not sure.

BTW, here's the exception that gets thrown:

System.Data.MetadataException was unhandled by user code  Message=Schema specified is not valid. Errors: EdmRelationshipNavigationPropertyAttribute for RelationshipType 'MemberRole' on NavigationProperty 'MemberRoleRoleList' in EntityType 'JumpForJoySoftware.T2T.EFDAL.Entity.MemberInfo' has a TargetRole name 'MemberRoleRoleList' that is not valid. Make sure that TargetRole name is a valid name. EdmRelationshipNavigationPropertyAttribute for RelationshipType 'MemberRole' on NavigationProperty 'RoleMemberMemberInfoList' in EntityType 'JumpForJoySoftware.T2T.EFDAL.Entity.Role' has a TargetRole name 'RoleMemberMemberInfoList' that is not valid. Make sure that TargetRole name is a valid name.   Source=System.Data.Entity  StackTrace:       at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)       at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)       at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)       at System.Data.Objects.ObjectContext.GetTypeUsage(Type entityCLRType)       at System.Data.Objects.ObjectContext.GetEntitySetForNameAndType(String entitySetName, Type entityCLRType, String exceptionParameterName)       at System.Data.Objects.ObjectContext.CreateObjectSet[TEntity](String entitySetName)       at JumpForJoySoftware.T2T.EFDAL.T2TEntities.get_MemberInfo() in E:\Programming\Trustee2Trustee\JumpForJoySoftware.T2T.EFDAL\T2TEntities.Generated.cs:line 158       at Trustee2Trustee.T2TMembershipProvider.ValidateUser(String username, String password) in E:\Programming\Trustee2Trustee\Trustee2TrusteeSite\providers\T2TMembershipProvider.cs:line 416       at Trustee2Trustee.Models.AccountMembershipService.ValidateUser(String userName, String password) in E:\Programming\Trustee2Trustee\Trustee2TrusteeSite\Models\AccountModels.cs:line 121       at Trustee2Trustee.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in E:\Programming\Trustee2Trustee\Trustee2TrusteeSite\Controllers\AccountController.cs:line 42       at lambda_method(Closure , ControllerBase , Object[] )       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)  InnerException: 

Mar 8, 2011 at 9:31 AM

Hi,
Seems we're doing similar, but your further ahead as you've got to the relationships....
I'm sure I recently got similar errors when I got a blank database going for the first time, and I changed my LINQ query to .FirstOrDefault() and result tested for null.
Let me know if that changes your error.
(Currently I'm wrestling with how I audit a Linker table (ie MemberInfoRole) that doesn't exist in the model !!)

John

Mar 8, 2011 at 6:46 PM

We are looking into this issue. Also the next version of EFDAL will have type tables generated out! Several people really want this and so it will be. The should be released by week's end I think.