Complex EF ICollection

Is this binding and filtering possible with Query Builder?

I have seen that there is filtering by nesting, could I use that with this object model?


(ICollection)




And I have another question:

-If I want to relate my parent class to another child class, it is enough for me to do this for bind or filter, right?:

QueryBuilderColumn Field="ClassParent.Child.Name"

In which cases is it recommended to replace this with nesting?


3 Replies

KV Keerthikaran Venkatachalam Syncfusion Team July 27, 2023 02:32 PM UTC

Hi Sergio,


We have checked the reported query and prepared a sample based on your requirements. Kindly refer to the below code snippet.

@using Syncfusion.Blazor.QueryBuilder

<SfQueryBuilder TValue="ClassParent" Separator="." @ref="QueryBuilderObj">

    <QueryBuilderRule Condition="or" Rules="@Rules"></QueryBuilderRule>

    <QueryBuilderColumns>

        <QueryBuilderColumn Field="Name" Label="Name" Type="ColumnType.String"></QueryBuilderColumn>

        <QueryBuilderColumn Field="Child" Label="Child" Type="ColumnType.Object">

            <QueryBuilderColumns>

                <QueryBuilderColumn Field="TypeID" Label="TypeID" Type="ColumnType.String"></QueryBuilderColumn>

                <QueryBuilderColumn Field="TypeName" Label="TypeName" Type="ColumnType.String"></QueryBuilderColumn>

            </QueryBuilderColumns>

        </QueryBuilderColumn>

    </QueryBuilderColumns>

</SfQueryBuilder>

@code {

    SfQueryBuilder<ClassParent> QueryBuilderObj;

    List<RuleModel> Rules = new List<RuleModel>()

    {

        new RuleModel { Field="Name", Label="Name", Type="String", Operator="equal", Value = "Mark"  }

    };

    public class ClassParent

    {

        public string Name { get; set; }

        public ClassChild Child { get; set; }

    }

    public class ClassChild

    {

        public string TypeID { get; set; }

        public string TypeName { get; set; }

    }

}


Get back to us if you need any further assistance on this.


Regards,

KeerthiKaran K V



SA Sergio Ayala August 6, 2023 07:18 AM UTC

hi, 

you have not understood, the class child is an IEnumerable



YA YuvanShankar Arunagiri Syncfusion Team August 8, 2023 03:11 PM UTC

Sorry for the inconvenience, Sergio. We don’t have support to load the IEnumerable model data source to the columns. The QueryBuilder component only supports the string, number, boolean, and object types of columns. And the object type is used for complex data-binding support, as we shared in our last update, which is similar to your requirement.


For more details about complex data binding in the query builder, kindly refer to the below links.

Demo link: https://blazor.syncfusion.com/demos/query-builder/complex-databinding?theme=fluent

UG link: https://blazor.syncfusion.com/documentation/query-builder/data-binding#complex-data-binding


The class definition should be like this.

public class ClassParent

    {

        public string? Name { get; set; }

        public virtual ICollection<ClassChild> Childs { get; set; } = new List<ClassChild>();

    }

 

    public class ClassChild

    {

        public AnotherClass? MyType { get; set; }

    }

 

    public class AnotherClass

    {

        public int TypeId { get; set; }

        public string? TypeName { get; set; }

    }


Using the complex data binding support of query builder, we can set the parent column's object type and child columns within the parent.

<SfQueryBuilder TValue="ClassParent" Separator="." >

    <QueryBuilderColumns>

        <QueryBuilderColumn Field="Name" Label="Name" Type="ColumnType.String"></QueryBuilderColumn>

        <QueryBuilderColumn Field="Childs" Label="Childs" Type="ColumnType.Object">

            <QueryBuilderColumns>

                <QueryBuilderColumn Field="MyType" Label="MyType" Type="ColumnType.Object">

                    <QueryBuilderColumns>

                        <QueryBuilderColumn Field="TypeId" Label="TypeId" Type="ColumnType.Number"></QueryBuilderColumn>

                        <QueryBuilderColumn Field="TypeName" Label="TypeName" Type="ColumnType.String"></QueryBuilderColumn>

                    </QueryBuilderColumns>

                </QueryBuilderColumn>

            </QueryBuilderColumns>

        </QueryBuilderColumn>

    </QueryBuilderColumns>

</SfQueryBuilder>


Check with attached sample code file and get back to us, if you need any further assistance on this. 


Regards,

YuvanShankar


Attachment: Index_3cdc1a67.zip

Loader.
Up arrow icon