© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
BekirK

OData filtering string variable

Hello, I have a .Net Web API project. And I am using OData library in a part of the project. I would like to ask you a question about filtering in OData.

My OData controller method:
[Route("odata/users")]
public class UsersODataController : ODataBaseController<User, UserListDto> // BBaseController doesn't incldue relatebla data just the repository implementation. So i didnt share it.
{
}
[Route("odata/users")]
public class UsersODataController : ODataBaseController<User, UserListDto> // BBaseController doesn't incldue relatebla data just the repository implementation. So i didnt share it.
{
}


UserListDto:
public class UserListDto
{
    public Guid Id { get; set; }
    public string Roles { get; set; }
    ...
}
UserListDto:
public class UserListDto
{
    public Guid Id { get; set; }
    public string Roles { get; set; }
    ...
}


Mapster mapping operation:
TypeAdapterConfig<User, UserListDto>
                .NewConfig()
                .Map(dest => dest.Roles, src => string.Join(",", src.Roles.Select(a => a.Role.Description)),   //  Here I take the description of the Role entity in User separated by commas
                    cond => cond.Roles.Any());
TypeAdapterConfig<User, UserListDto>
                .NewConfig()
                .Map(dest => dest.Roles, src => string.Join(",", src.Roles.Select(a => a.Role.Description)),   //  Here I take the description of the Role entity in User separated by commas
                    cond => cond.Roles.Any());


Here, by mapping, I combine multiple roles of the user with commas. (The result is as in the image)
So far, so good. But the real problem starts when I want to filter. And this problem is caused by the strıng Role variable that I separated with commas, I understood this as a result of the debug. but I could not solve the problem. request from those who have information about OData. I want to filter between users with roles such as "test-1,test-2", "test-1", "test-3,test-5".

filtering EndPoint: http://localhost:5000/odata/users?$count=true&$top=10&$skip=0&$filter=(roles%20eq%20%27test-2%27)&$select=id,nameSurname,email,roles&$expand=jobtitle($select=translations)
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

OData filtering
C#CC# / help
3y ago
❔ Parsing an OData filter string
C#CC# / help
3y ago
Odata nextlink
C#CC# / help
3mo ago
OData Dictionary Response
C#CC# / help
2y ago