Solved

How to get the first row of a Matrix with LINQ

Posted on 2013-01-25
3
448 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now