C
C#2y ago
Zigo

Linq to select where Name contains substring?

var dynContentList = await _context.DynamicContents
.OrderBy(x => x.OrderIndex)
.Any(i => i.Name.Contains(substring))
.ToListAsync();
var dynContentList = await _context.DynamicContents
.OrderBy(x => x.OrderIndex)
.Any(i => i.Name.Contains(substring))
.ToListAsync();
I want to return all rows where the Name field contains a substring
5 Replies
Saber
Saber2y ago
ok lets think about this logically, why would you be using Any instead of Where which you explicitly say in the description of what you want
TheBoxyBear
TheBoxyBear2y ago
^
Zigo
Zigo2y ago
i'm helpless with Linq
TheBoxyBear
TheBoxyBear2y ago
Any as the name implies just returns a bool, true if any of the items meet the condition
Zigo
Zigo2y ago
ah ok thank you wow it worked!