What I have: List
Class: Rule
–>
Class: Term
—>
Property Compare_Src
Property Compare_Mode
What I want to do:
use a Linq statement to get my Rules, grouped by a Combination of its Compare_Src and Compare_Mode.
Static Example for one Combination: (Here I get a list for all rules with Compare_src = EmpfaengerToken and Compare_mode = equals. What I want is a full list with all rules, grouped by the two propertys, instead of hardcoded values.
var regeln_empfaengertoken =
(
from rule in rules
where
(
from term in rule.Term
where
(
term.Compare_src == Entities.Enums.Compare_src.EmpfaengerToken
&&
term.Compare_mode.ToString() == "equals"
)
select term
).Count() > 0
select rule
).ToList<Entities.Rule>();
I know it’s possible, but can’t find the right solution 🙁
[Serializable]
public class Rule
{
private List<Term> _term = new List<Term>();
...
}
[Serializable]
public class Term
{
private Entities.Enums.Compare_src _compare_src;
private Entities.Enums.Compare_mode _compare_mode;
private Entities.Enums.Compare_Type _compare_type;
.........
}
Try something like this:
What I did here (tried anyway, didn’t check if this actually works with your model) is to inverse the query. First get all the terms, group them by the mutiple field key and then select the relevant rules for each group.