好的,所以我很困惑,四处寻找这个,我知道我正在实现一些非常简单的东西,比它需要的更复杂。基本上我有一个 POCO 对象,它有一个包含其他成员字符串的成员。这被标记为“st”,它可能在一个字符串中包含以逗号分隔的系列字符串。因此,我可能有两个字符串成员是“图像,报告”和另一个“cms,crm”。我有一个对象列表,我想匹配这些字符串的一部分,但不一定都作为 DISTINCT LIST。因此,“cms”的成员将返回包含“cms”的任何内容的值,因此将返回“cms, crm”。
我想将其连接起来,以便可以查询通用列表,但我无法让它工作并且正在查看其他线程,但在我的情况下这些方法不起作用。我一直认为这很简单,但我完全想念它。如果有人有更好的想法,请告诉我。我在看这里,但无法正确应用逻辑:
我一直在尝试不同级别的延续范围内的“Select”、“SelectMany”、“Contains”、“Any”、“All”的方法,但无济于事。这是一个简单的控制台应用程序示例的简单摘录:
public class Program
{
public class StringModel
{
public string name { get; set; }
public string str { get; set; }
}
static void Main(string[] args)
{
string s = "";
List<StringModel> sm = new List<StringModel>
{
new StringModel
{
name = "Set1",
str = "images, reports"
},
new StringModel
{
name = "Set2",
str = "cms, crm"
},
new StringModel
{
name = "Set3",
str = "holiday, pto, cms"
}
};
sm.ForEach(x => s += x.name + "\t" + x.str + "\n");
var selected = new List<object> {"cms", "crm"};
s += "\n\nITEMS TO SELECT: \n\n";
selected.ForEach(x => s += x + "\n");
s += "\n\nSELECTED ITEMS: \n\n";
// works on a single item just fine
var result = sm.Where(p => p.str.Contains("cms")).Select(x => new { x.name, x.str}).ToList();
// I am not using select to get POCO on other methods till I can get base logic to work.
// Does not return anything
var result2 = sm.Where(p => selected.Any(x => x == p.str)).ToList();
// Does not return anything
var result3 = sm.Where(p => selected.Any(x => selected.Contains(p.str))).ToList();
result.ForEach(y => s += y + "\n");
s += "\n\n2nd SET SELECTED: \n\n";
result2.ForEach(y => s += y + "\n");
s += "\n\n3rd SET SELECTED: \n\n";
result3.ForEach(y => s += y + "\n");
Console.WriteLine(s);
Console.ReadLine();
}
}