EntityFramework.DynamicFilters icon indicating copy to clipboard operation
EntityFramework.DynamicFilters copied to clipboard

Filtering on bi-directional 1:0-1 relationships

Open rhyskoedijk opened this issue 8 years ago • 4 comments

I've just checked out the source code and I can see there is a known issue (and unit test) for supporting relationships without having the foreign key specified on the model.

I am wondering if this the same reason why bi-directional 1:0-1 relationships don't work, or if this is due to another issue? Here is an example of a broken model based off the existing unit tests:

    public class EntityE : EntityBase
    {
        public int ChildID { get; set; }
        public EntityEChild Child { get; set; }
    }

    public class EntityEChild : EntityBase
    {
        public EntityE Parent { get; set; } // Link-back to my parent
        public int ChildValue { get; set; }
    }

modelBuilder.Entity<EntityE>().HasOptional(x => x.Child).WithOptionalPrincipal(x => x.Parent);

Could I modify DynamicFilterQueryVisitorCSpace to skip over the dependent side of the navigation property? There would be no need to follow Parent backwards as filtering should have already been applied prior to reaching EntityEChild in this instance right?

Any guidance/ideas on how I can (temporarily) resolve this issue would be grateful.

rhyskoedijk avatar Aug 13 '17 05:08 rhyskoedijk

I've narrowed this down further. It works if the relationship is required on both sides, or a mixture of optional/required: modelBuilder.Entity<EntityE>().HasRequired(x => x.Child).WithRequiredPrincipal(x => x.Parent); modelBuilder.Entity<EntityE>().HasOptional(x => x.Child).WithRequired(x => x.Parent);

But it does not work if the relationship is optional on both sides modelBuilder.Entity<EntityE>().HasOptional(x => x.Child).WithOptionalPrincipal(x => x.Parent);

rhyskoedijk avatar Aug 13 '17 08:08 rhyskoedijk

Hello @rhyskoedijk ,

Thank you for reporting,

We will try to look at it in the beginning of next week.

Best Regards,

Jonathan

JonathanMagnan avatar Aug 13 '17 13:08 JonathanMagnan

Hello @rhyskoedijk ,

Sorry for my late answer,

I have investigated this issue again today but it looks, for now, it's too much complex to solve as the constraint is null, unlike the second scenario that is working.

I believe, for now, we will abandon it but we may be trying to support it again in a few months.

Best Regards,

Jonathan

JonathanMagnan avatar Sep 12 '17 19:09 JonathanMagnan

Understandable, we've worked around it for now by adjusting our domain model to not use optional 1:0-1 relationships. Not ideal, but gets us over the line for now.

Thanks for looking in to it

rhyskoedijk avatar Sep 12 '17 20:09 rhyskoedijk