Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将字符串中的第一个字符按另一个字符串中的任何字符分组_C#_Linq To Sql - Fatal编程技术网

C# 将字符串中的第一个字符按另一个字符串中的任何字符分组

C# 将字符串中的第一个字符按另一个字符串中的任何字符分组,c#,linq-to-sql,C#,Linq To Sql,在给定字符串列表的Linq2Sql中,我需要一个查询,该查询返回系统以字符串中的任何字符开头的所有字符串 这就是我想到的:这个函数需要帮助 void Main() { var strings = new List<string>(){"ABCDE", "FGHIJ", "KLMNO"}; var values = GetUsedStrings(strings); /* * In my case expected to return strings "

在给定字符串列表的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)
    {
         string aa = @"if exists(select * from tblSystems where  
                    systemName is not null and LEN(systemName)>0";

         for (int i = 0; i < characters.Length; i++)
         {
             aa += " and SUBSTRING([login],1,1) = '" + characters[i] + "'";
         }
         aa+=")";
         return db.ExecuteQuery<bool>(aa).Single();
    }
我问题中的GetUsedStrings函数就是我正在使用的trubble函数。有开始吗?工作如期进行
    private bool StartsWithAny(string characters)
    {
         string aa = @"if exists(select * from tblSystems where  
                    systemName is not null and LEN(systemName)>0";

         for (int i = 0; i < characters.Length; i++)
         {
             aa += " and SUBSTRING([login],1,1) = '" + characters[i] + "'";
         }
         aa+=")";
         return db.ExecuteQuery<bool>(aa).Single();
    }