Link to home
Start Free TrialLog in
Avatar of iscivanomar
iscivanomarFlag for United States of America

asked on

How to get the first row of a Matrix with LINQ

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
ASKER CERTIFIED SOLUTION
Avatar of Srinivasulu Muppala
Srinivasulu Muppala
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iscivanomar

ASKER

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
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.