none
Group by C# LinQ RRS feed

  • Question

  • Hey everybody !

    i'm working on a code to print out labels. And so far so good.. i'm getting te labels but not the correct amount. 

    He now prints 2 labels which are the same..
    Label 1 :

    Client
    SampleId: 0001
    Analyse: E.coli, Sa, Aeroob

    Label 2 :

    Client
    SampleId: 0001
    Analyse: E.coli, Sa, Aeroob

    -----
    But in in our system i have entered 1 Order with 1 sample and 2 Analyses (E.coli and Aeroob). So i want one label in stead of 2 with this information: 

    Client
    SampleId: 0001
    Analyse: E.coli, Aeroob

    -------

    This is the code. 

    <document xmlns:db="urn:Company.db" xml:space="preserve">
      <pages></pages>
      <labels>
      <!-- *********************************************** -->
      <!-- * Samples                                     * -->
      <!-- *********************************************** -->
      <db:for-each-linq>
        <db:statement><![CDATA[
           from x in 
                        (
                            from t in Tests
                            where t.Sample.Order.OrderId == _p0 && t.Sample.Product==null 
                            
                            let grp = (t.TestType.Name == "E.coli telling, TBX" || t.TestType.Name == "Coagulase pos. Staphylococcen" || t.TestType.Name == "Aeroob kiemgetal telling, PCA") ? "E.coli, SA, Aeroob" : t.TestType.Name
                            select new 
                            {
                                Number = t.Sample.SampleId,
                                Description = t.Sample.Name,
                                Client = t.Sample.Order.ClientContact.Name,
                                Test=grp,
                                Order=t.Sample.Name,
                                Sample = t.Sample
          
                            }               
                        )
                        group x by new {tt = x.Test, s = x.Sample} into g
                        select new 
                        {
                            Number = g.Key.s.SampleId,
                            Description = g.Key.s.Name,
                            Client = g.Key.s.Order.ClientContact.Name,
                            Test=g.Key.tt,
                            Order=g.Key.s.Name,
      
                        }
          ]]></db:statement>
        <db:parameters>
          <db:parameter name=":p0" select="arguments[0].value" />
        </db:parameters>
        
          <label>
      <line><![CDATA[^XA]]></line>
        <line><![CDATA[^MD10]]></line>
        <line><![CDATA[^LT20]]></line>
        <line><![CDATA[^FT40,80^A0N,48,48^FB500,2,,]]></line>
        <line><![CDATA[^CFA,35^FD]]><db:value-of select="Client" /><![CDATA[^FS]]></line>
        
        <line><![CDATA[^CFA,30^FT40,130^A0N,48,48^FB500,,,]]></line>
        <line><![CDATA[^CFA,30^FD]]>Deelmonster  :<br> </br><db:value-of select="Number" /><![CDATA[^FS]]></line>
        
        <line><![CDATA[^FT40,240^A0N,48,48^FB500,2,,]]></line>
        <line><![CDATA[^CFA,30^FD]]><db:value-of select="Order" /><![CDATA[^FS]]></line>
        
        <line><![CDATA[^FT40,270^A0N,48,48^FB500,2,,]]></line>
        <line><![CDATA[^CFA,30^FD]]><br>Product:</br><db:value-of select="Description" /><![CDATA[^FS]]></line>
        
        <line><![CDATA[^FT40,350^A0N,48,48^FB500,2,,]]></line>
        <line><![CDATA[^CFA,20^FD]]>Analyse:<db:value-of select="Test" /><![CDATA[^FS]]></line>
        
        
        <line><![CDATA[^FT75,290^A0N,48,48^FB500,2,,]]></line>


        <line><![CDATA[^XZ]]></line>
          
       </label>
        </db:for-each-linq>
        </labels>
    </document>

    Tuesday, March 24, 2020 9:36 AM

All replies