Query for List<Guid> Value

Hello I have a component: 

<SfDropDownList @bind-Value="Value" TValue="Guid?" TItem="DropdownItem<Guid?>" DataSource="DataSource" Query="Query">

            <DropDownListFieldSettings Text="Text" Value="Value" />

        </SfDropDownList>

public class DropdownItem<T>

    {

        public string Text { get; set; }

        public T Value { get; set; }

        public bool IsChecked { get; set; }

        public Dictionary<string, object> AdditionalData { get; set; } = new();

    }


and based on certain conditions I want apply where clause to the datasoure:

var GuidList = new List<Guid?>();

... Code to populate list ...

var WhereQr = new WhereFilter()

            {

                Field = "Value",

                value = GuidList,

                Operator = "????"

            };

Query = new Query().Where( WhereQr );


I treid contains, in, equal and none of them work?? it works fine for equal/notequal for a single guid value but not for a list

which operator I should use for List<Guid> values? or maybe there is a different approach?





1 Reply

KP Kokila Poovendran Syncfusion Team August 1, 2023 12:50 PM UTC

Hi Eimantas Baigys,


To apply a WHERE clause to the data source when working with a list of GUID values, you can use the "Or" operator in combination with predicates. Based on your provided code, we have created a sample and code snippet to demonstrate how to achieve this. 


Code snippet: 


<SfDropDownList @bind-Value="@DropDownValue" TValue="string" TItem="Country" DataSource="@Countries" Query="@DropdownQuery">

 

            <DropDownListFieldSettings Text="Name" Value="Name" />

            <DropDownListEvents TItem="Country" TValue="string" OnValueSelect="OnSelect"></DropDownListEvents>

 

</SfDropDownList>

 

 

@code {

 

    public Query DropdownQuery { get; set; } = new Query();

    public List<Guid> Orders1 { get; set; } = new List<Guid>();

 

    public class Country

    {

        public string Name { get; set; }

 

        public Guid Code { get; set; }

    }

 

    List<Country> Countries = new List<Country>

    {

        new Country() { Name = "Australia", Code = Guid.NewGuid() },

        new Country() { Name = "Bermuda", Code = Guid.NewGuid() },

        new Country() { Name = "Canada", Code = Guid.NewGuid() },

        new Country() { Name = "Cameroon", Code = Guid.NewGuid() },

        new Country() { Name = "Denmark", Code = Guid.NewGuid() }

    };

 

    public string DropDownValue = "Bermuda";

 

    public void OnSelect(SelectEventArgs<Country> args)

    {

        Orders1.Add(args.ItemData.Code);

    }

 

 

    public void Filter()

    {

        var ColPre = new WhereFilter();

 

        List<WhereFilter> Predicate = new List<WhereFilter>();

 

        foreach( var a in Orders1)

        {

            Predicate.Add(new WhereFilter()

                {

                    Field = "Code",

 

                    value = a,

 

                    Operator = "equal",

 

                    IgnoreCase = true

                });

 

        }

 

        ColPre = WhereFilter.Or(Predicate);

 

        DropdownQuery = new Query().Where(ColPre);

   

    }

 

}

 

 


In this code, we have added an external button that calls the Filter() method. When you select values from the dropdown, the selected GUIDs will be saved to the Orders1 list. After that, when the external button is clicked, the Filter() method generates predicates using the Or operator, which combines all the conditions for each GUID in the list. Finally, the generated predicate is added to the DropdownQuery, which applies the WHERE clause to the data source.


Please refer to the provided code snippet for a better understanding. If you have any further questions or need additional assistance, please reach out to us. 



Regards,

Kokila Poovendran.


Attachment: BlazorServerProject_37ca32f9.zip

Loader.
Up arrow icon