locked
Navigation Properties don't work on EntityFrameworkDataContext in ChangeInterceptors RRS feed

  • Question

  • There appears to be an issue when using lazy loading in change interceptors using the EntityFrameworkDataService. I have change interceptors setup which utilize navigation properties to navigate to a route entity which has permissions assigned to it. When I try to delete an entity the navigation properties appear to not work randomly. Below is  snippet of a change interceptor that works when updating an entity but the fails when I am attempting to delete the entity because the navigation properties always evaluate to null. In the case of the snippet below ParentObj resolves in updates but not deletes. Is this by design and is there anyway around this? Thanks.

    [ChangeInterceptor(nameof(AdminDataContext.TaskAssignmentTypeDefinitions))]
            public void OnChangeTaskAssignmentTypeDefinition(TaskAssignmentTypeDefinition entityDef, UpdateOperations operations)
            {
                if (!PermissionBaseQuery.Any(a =>
                        a.Permission == SecurityConstants.BusinessDomainWritePermission &&
                        a.PermId == entityDef.ParentObj.PermId))
                {
                    throw new DataServiceException(400, string.Format(PermissionDeniedStringTemplate, UserName, nameof(TaskAssignmentTypeDefinition), entityDef.Id));
                }
            }

    PermissionBaseQuery is a linq expression which references CurrentDataSource

    Thursday, January 28, 2016 2:15 AM

All replies

  • Hi Grep,

    >>Below is snippet of a change interceptor that works when updating an entity but the fails when I am attempting to delete the entity because the navigation properties always evaluate to null. In the case of the snippet below ParentObj resolves in updates but not deletes. Is this by design and is there anyway around this?

    You could try to retrieve the data by using eagerly loading pattern. It will retrieve all the related navigation properties, and check if it works fine for you. You could refer to the link as below about eagerly loading for detail.

    https://msdn.microsoft.com/zh-cn/data/jj574232

    Best regards,

    Cole Wu

    Thursday, January 28, 2016 6:54 AM
    Moderator