Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
allTopics = await _dbContext.Collection.Find(x => x.ParentContentIds.Contains(String.Join(",", filter.SolutionIds))).ToListAsync();

Here ParentContentIds and filter.SolutionIds are List<string>

But even if having data, no data returned. I want to check all items from Collection with a condition that only records with ParentContentIds in filter.SolutionId.

Can anybody help me?

What I have tried:

C#
allTopics = await _dbContext.Collection.Find(x => x.ParentContentIds.Contains(String.Join(",", filter.SolutionIds))).ToListAsync();
Posted
Updated 12-Jul-22 6:14am
v2

string.Join converts a collection of strings into a single string, separated by one or more of the separator string you specify.
So if filter.SolutionIds contains three strings "1", "2", and "3", then String.Join(",", filter.SolutionIds) will return a string containing a single string "1,2,3".

And string.Contains looks for an exact string match as a subset of the input string - in the example above:
"1,1,2,3,b"  will match.
"1,2,3"      will match.
"1,1,2,3,b"  will not match.
"1,1,2"      will not match.
"1"          will not match.
"2"          will not match.
"3"          will not match.

You probably need to decide exactly what you want to find, but if you only want to process ParentContentIds that exist in your Solution IDs, then reverse the check:
filter.SolutionIds.Contains(x.ParentContentIds)

But that's just a guess since we have no idea what your fields contain, or what exactly you are trying to do with them!
 
Share this answer
 
Difficult to say without seeing the structure of your model, but perhaps something like this?
C#
allTopics = await _dbContext.Collection
    .Where(x => x.ParentContentIds.Any(p => filter.SolutionIds.Contains(p)))
    .ToListAsync();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900