C#C
C#3y ago
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. { }

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());

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
Was this page helpful?