Note that there are some explanatory texts on larger screens.

plurals
  1. POC# LINQ for tree oriented data structure of classes
    primarykey
    data
    text
    <p>I have List where myObj has it own list of objects called example mySubObj. Object mySubObj has prop string Name.</p> <p>So I want to create new List base on prop string Name from mySubObj.</p> <p>I wrote this code, but it seems that it's wrong:</p> <pre><code>var por = msgs.Where(x =&gt; x.Parameters .Where(p =&gt; p.ParameterName == s).Count() == 1); </code></pre> <p>Can anyone help me with LINQ?</p> <p>EDIT: This is whole code:</p> <pre><code> foreach (string s in parameters) { using (StreamWriter streamWriter = new StreamWriter(outputFolder + "/" + s + ".xls")) { streamWriter.Write("No.\tMessage\tMS\tTime\tSC"); var por = (from m in msgs from p in m.Parameters where p.ParameterName == s select m).Distinct(); List&lt;string&gt; headeri = new List&lt;string&gt;(); List&lt;string&gt; vrijednosti = new List&lt;string&gt;(); foreach (L3Message p in por) { foreach (Parameter pam in p.Parameters) { TraverseForHeaders(pam, ref headeri); } } foreach (string head in headeri) { streamWriter.Write("\t" + head); } streamWriter.Write("\n"); </code></pre> <p><strong>Edit 2:</strong></p> <p>Here is two of my classes, with this it should be more specified:</p> <pre><code>public class L3Message { public int Number { get; set; } public string MessageName { get; set; } public string Device { get; set; } public string Time { get; set; } public string ScramblingCode { get; set; } public List&lt;Parameter&gt; Parameters { get; set; } public L3Message() { Parameters = new List&lt;Parameter&gt;(); }} public class Parameter { public int numOfWhitespaces { get; set; } public string ParameterName { get; set; } public string ParameterValue { get; set; } public Parameter Parent { get; set; } public List&lt;Parameter&gt; SubParameters { get; set; } public Parameter() { SubParameters = new List&lt;Parameter&gt;(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload