В Linq2Sql с заданным списком строк мне нужен запрос, который возвращает все строки системы, которая начинается с любого из символов в строке.
Вот что я придумал: (Нужна помощь с этой функцией)
void Main()
{
var strings = new List<string>(){"ABCDE", "FGHIJ", "KLMNO"};
var values = GetUsedStrings(strings);
/*
* In my case expected to return strings "ABCDE" and "KLMNO"
* since there exists Systems that starts
* with any of the characters in those strings.
*/
values.Dump();
}
public IList<string> GetUsedStrings(IList<string> strings)
{
var q = from s in tblSystems
where s.systemName != null && s.systemName.Length > 0
group s by s.systemName[0] into g //Somehow need to group by the characters strings list?
select g.Key;
return q.ToList();
}
Проверка одной строки: (работает как положено)
private bool StartsWithAny(string characters)
{
return
(from s in tblSystems
where
s.systemName != null && s.systemName.Length > 0 &&
characters.Contains(s.systemName[0])
select s).Any();
}