System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

create-dynamic-expression-one-to-many-relations-with-child-class-property

Open aysegulgurmeric opened this issue 3 years ago • 3 comments

Is it possible to create a dynamic where condition with a collection property?

I'm trying to filter Parents which Childs.ChildProp1 == "test". What's the correct syntax ?

https://dotnetfiddle.net/Zh7Jy5

public class Parent
{
    public string MasterProp1 { get; set; }
    public string MasterProp2 { get; set; }
    public IEnumerable<Child> Childs { get; set; }  
}


public class Child
{
    public string ChildProp1 { get; set; }
    public int ChildProp2 { get; set; }
}

Parents.Where("Childs.ChildProp1==\"test\"")

aysegulgurmeric avatar Feb 25 '22 13:02 aysegulgurmeric

Do you want the Parents who have a Child in Childs whose ChildProp1 matches "test"?

Parents.Where("Childs.Any(ChildProp1 == \"test\")")

Or do you want all the Childs whose ChildProp1 matches "test"?

Parents.SelectMany("Childs").Where("ChildProp1 == \"test\"")

zspitz avatar Feb 26 '22 17:02 zspitz

@aysegulgurmeric Can you provide a working fiddle which represents this issue?

The fiddle you provided looks different?

StefH avatar Jun 04 '23 08:06 StefH

@aysegulgurmeric Can you provide a working fiddle which represents this issue?

The fiddle you provided looks different?

StefH avatar Sep 10 '23 10:09 StefH