我有以下代碼,我需要獲得所有與兩個屬性匹配的IndividualRefs - 它需要使用AND而不是OR來獲得所有。例如下面的代碼應該只給我個人參考22,因爲他匹配「ST」和「BJOG」從列表中獲得匹配兩個屬性的值使用c#LINQ
你知道一個LINQ語句嗎?
string AttributeList = "ST,BJOG,";
List<StratogIndividuals> inds = new List<StratogIndividuals>();
StratogIndividuals s = new StratogIndividuals();
string[] attributes = AttributeList.Split(',').Where(x => x != "").ToArray();
s.AttributeCode = "ST";
s.IndividualRef = "22";
inds.Add(s);
s = new StratogIndividuals();
s.AttributeCode = "BJOG";
s.IndividualRef = "22";
inds.Add(s);
s = new StratogIndividuals();
s.AttributeCode = "BJOG";
s.IndividualRef = "20";
inds.Add(s);
s = new StratogIndividuals();
s.AttributeCode = "XXF";
s.IndividualRef = "21";
inds.Add(s);
當然AttributeList的大小可以增加。 謝謝
'inds.GroupBy(IND => ind.IndividualRef)。凡(G =>新的HashSet(g.Select(IND => ind.AttributeCode))。SetEquals(新[] { 「BJOG」 ,「ST」}))。Select(g => g.Key)' –
spender
使用GroupBy inds.GroupBy(x => new {attr = x.AttributeCode,ref = x.INdividual}) – jdweng