Solved

How to get the first row of a Matrix with LINQ

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to go to Web page 2 50
Round up to 100% in .NET 10 43
Format column on datatable 7 15
COnsume rest client 6 8
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

11 Experts available now in Live!

Get 1:1 Help Now