让我们从将用于过滤结果的字符串列表开始:
 List<String> RadioNames = new List<String>();
 RadioNames.AddRange(new String[] { "abc", "123", "cba", "321" });
我希望能够过滤一个 LINQ to SQL 数据库表,RadioNames但问题是我想要RadioNames部分匹配(这意味着它将捕获 Radio123 而不仅仅是 123)。
我需要过滤的来源如下:
var ChannelGrants = from cg in sddc.ChannelGrants
                    select new
                    {
                        cg.ID,
                        cg.Timestamp,
                        cg.RadioID,
                        cg.Radio
                    };
所以我需要执行类似于下面的操作(在原始ChannelGrants结果之外,因为这是一个条件搜索)
 if(RadioNamesToSearch != null)
 {
      List<String> RadioNames = new List<String>();
      // Here I split all the radio names from RadioNamesToSearch based on a command separator and then populate RadioNames with the results
      ChannelGrants = from cg in ChannelGrants
                      where ???
                      select cg;
 }
我需要帮助在哪里???在上面的代码中(或者如果ChannelGrants = ...一起无效)。重复以上步骤,我需要过滤ChannelGrants以返回任何匹配项,RadioNames但它会进行部分匹配(这意味着它将捕获 Radio123 而不仅仅是 123)。
所有代码都包含在这样的方法中......
 public static DataTable getBrowseChannelGrants(int Count = 300, String StartDate = null, String StartTime = null, String EndDate = null, String EndTime = null, String RadioIDs = null, String RadioNamesToSearch = null, String TalkgroupIDs = null, String TalkgroupNames = null, bool SortAsc = false)