✅ Filtering problems in .Net Core
Hello everyone,
I'm in the midst of a coding project and have encountered a challenge. I'm attempting to narrow down checklist questions by product type, but I'm encountering an issue with null product types. Even when I provide a productTypeId, I'm still getting checklist questions with null productTypeId.
Any insights or suggestions would be highly valued. Your assistance is greatly appreciated!
Thank you in advance!
7 Replies
Result
I wouldn't use
x
as my lambda argument for both lambdas here, as the outer one is still in scope.
and that where doesn't do what you think it does
it just says at least one item in the collection must have a non-null, non zero ProductTypeId
and thats exactly what your response is as well, there was a checklist with at least one non-null, non-zero questionBut it is possible to filter out those ProductTypeId that has a null value?
I've also tried
But here is based on ProductTypeName
I thought passing ProductTypeId instead of ProductTypeName will work
You do understand that
Any
returns true if one or more items match right?
so it wont filter out only the items that match
your filtering must be added to the includeQueryable
Oh, I misunderstand its uses.
Here I only get the ChecklistQuestions that has ProductTypeId right? Should I create another API for ChecklsitQuestions that has null ProductTypeId? Since I need them also. I just want to exclude them when creating a filter base on ChecklistType.
You need to include any filtering you want for your child-items when you include them
so if you want that to be conditional, you must make the include conditional
The first approach I use is I include the items I need into a IQueryable and I use If else for the conditionals. I will revise my first implementation. Thanks