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)1 Reply
Error Message: errors": ["The LINQ expression 'DbSet<User>()\r\n .Where(u => !(u.IsDeleted))\r\n .Where(u => DbSet<UserRole>()\r\n .Where(u0 => !(u0.IsDeleted))\r\n .Where(u0 => EF.Property<Guid?>(u, "Id") != null && object.Equals(\r\n objA: (object)EF.Property<Guid?>(u, "Id"), \r\n objB: (object)EF.Property<Guid?>(u0, "UserId")))\r\n .Any() ? string.Join(\r\n separator: ",", \r\n values: DbSet<UserRole>()\r\n .Where(u1 => !(u1.IsDeleted))\r\n .Where(u1 => EF.Property<Guid?>(u, "Id") != null && object.Equals(\r\n objA: (object)EF.Property<Guid?>(u, "Id"), \r\n objB: (object)EF.Property<Guid?>(u1, "UserId")))\r\n .Join(\r\n inner: DbSet<Role>()\r\n .Where(r => !(r.IsDeleted) && r.PropertyId == 00000000-0000-0000-0000-000000000000 || (Guid?)r.PropertyId == (Guid?)c8109bdf-1d8e-42c9-bc9d-be70fb1333bb), \r\n outerKeySelector: u1 => EF.Property<Guid?>(u1, "RoleId"), \r\n innerKeySelector: r => EF.Property<Guid?>(r, "Id"), \r\n resultSelector: (o, i) => new TransparentIdentifier<UserRole, Role>(\r\n Outer = o, \r\n Inner = i\r\n ))\r\n .Select(u1 => u1.Inner.Description)) : null == __TypedProperty_0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information."]
Database: PostgreSQL
Has anyone to help me ;)