Solved

How to get the first row of a Matrix with LINQ

Posted on 2013-01-25
3
460 Views
Last Modified: 2013-01-29
Hello everyone,
               I need to see if the pallet is stackable or not. If I get two pallets the following LINQ work fine but if we have only one pallet with information does not work.

 var stackableUDC = (from ms in Model.CurrentMissions
                                where (ms.CurrentStationId == StationId 
                                && ms.Lgv.Station.Positions.Select(y =>  y.TrackingId > 0 
                                                                    && y.TrackingInfo.StackableType > 0
                                                                    && y.TrackingInfo.StackableType == (int)EStackableType.doubleStack
                                                                    && y.TrackingInfo.StackableType != (int)EStackableType.singleStack                                                                      
                                ).First()                                 
                                      )                
                                orderby ms.Lgv.Station.Positions
                                select ms.Lgv.Station.Positions
                                
                                ).FirstOrDefault();

Open in new window


I need to get the single pallet two if is Stackable.

Please see the picture for better explanation.

Thank you
LinqMatrix.png
0
Comment
Question by:iscivanomar
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
Srinivasulu Muppala earned 500 total points
ID: 38820573
break the linq into two iterations such as  break your first iteration upto
.....Positions return it positions and

apply linq again on the result positions.matrix

.Select(y =>  y.TrackingId > 0
                                                                    && y.TrackingInfo.StackableType > 0
                                                                    && y.TrackingInfo.StackableType == (int)EStackableType.doubleStack
                                                                    && y.TrackingInfo.StackableType != (int)EStackableType.singleStack                                                                      
                                )
include the empty check with above specified checks otherwise if second element is stackable(empty) same issue will come
0
 

Author Comment

by:iscivanomar
ID: 38831523
Hello srinipro,
           sorry to get back to you until today. I went to other project for two days.  
I breaked down to this:

 var stackable = (from ms in Model.CurrentMissions
                                    where (ms.CurrentStationId == StationId)
                                    orderby ms.Lgv.Station.Positions
                                    select ms.Lgv.Station.Positions).FirstOrDefault();

                var stackableUDC = (from st in stackable
                                     where (st.TrackingInfo != null
                                            && st.TrackingInfo.TrackingId > 0
                                            && st.TrackingInfo.StackableType > 0
                                            && st.TrackingInfo.StackableType == (int)EStackableType.doubleStack
                                            && st.TrackingInfo.StackableType != (int)EStackableType.singleStack)
                                     orderby st.TrackingInfo.TrackingId
                                     select st.TrackingInfo.TrackingId
                                    ).FirstOrDefault();

Open in new window


however, I am getting an error called:  
failed to compare two elements in the array in the second LINQ.
I am not using IComparable. what does this mean?

Thank you
0
 

Author Closing Comment

by:iscivanomar
ID: 38833357
Hello srinipro,
       I break the LINQ SQL as you said and it work. I was able to check and compare the data more easily. Thank you again and have a good day.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question