Solved

How to get the first row of a Matrix with LINQ

Posted on 2013-01-25
3
490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

718 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