Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How do i sort the result of LINQ when my collection of data is combination of numbers and letters.

Below is the design of my tables and my method to populate the line.

Lines
--------------------------------
|LineID | LineName  | LineType |
--------------------------------
| 167   | 1         | 3        |
| 172   | 2         | 3        |
| 13    | 3         | 3        |
| 231   | 4         | 3        |
| 18    | 5         | 3        |
| 23    | 6         | 3        |
| 44    | 7         | 3        |
| 49    | 8         | 3        |
| 116   | 9         | 3        |
| 120   | 10        | 3        |
| 266   | 13        | 3        |
| 195   | 11        | 7        |
| 265   | 12        | 7        |
| 2     | B         | 1        |
| 3     | C         | 1        |
--------------------------------


Line Type
-------------------------
|LineType | LineDesc    |
-------------------------
| 3       | FP          |
| 7       | BF          |
| 1       | Process     |
-------------------------


Process
---------------------------------------
|ProcessID | ProcessName| ProcessType |
---------------------------------------
| 10       | Filling    | 3           |
| 25       | BulkFilling| 7           |
| 4        | Process    | 1           |
---------------------------------------



Below is the method that i use when populating the Line. It has a parameter "processid".

private void LoadLinePerProcess(int processid)
{
   List<Classes.Lines> line = Classes.Lines.GetLineCollection();
   List<Classes.Process> process = Classes.Process.GetProcessCollection();
   List<Classes.ProcessLineType> processtype = Classes.ProcessLineType.GetProcessLineTypeCollection();

   var qLine = from p in process
               join t in processtype on p.ProcessType equals t.LineTypeCode
               join l in line on t.LineTypeDescription equals l.LineType into LineColl
               orderby p.ProcessType
               select new
               {
                  ProcessID = p.ProcessID,
                  ProcessName = p.ProcessName,
                  ProcessType = p.ProcessType,
                  LineName = from ln in LineColl
                             orderby ln.LineName
                             select new { ln.LineID, ln.LineName }
                };

            foreach (var result in qLine)
            {
                if (result.ProcessID == processid)
                {
                    c_cboLine.Items.Clear();
                    foreach (var lines in result.LineName)
                    {
                        c_cboLine.Items.Add(lines.LineName);
                    }
                    break;
                }
            }
            if (c_cboLine.Items.Count > 0) { c_cboLine.SelectedIndex = 0; }
}


My problem now is, when my "processid" is equal to 10, it generate the line as "1,13,2,3,4,5..." it looks like it converted to string not int.

Thanks
Posted

orderby p.ProcessType != 1 ? int.Parse(ln.LineName) : char.Parse(ln.LineName)


this solved my problem.

Thanks!
 
Share this answer
 
Comments
arindamrudra 28-Jul-11 2:08am    
Thanks for sharing your answer.
Can you have a look at this[^] link.
 
Share this answer
 
Comments
klaydze 28-Jul-11 0:27am    
Thanks for the link.

I solved my problem by using this code.

orderby p.ProcessType != 1 ? int.Parse(ln.LineName) : char.Parse(ln.LineName)
arindamrudra 28-Jul-11 2:07am    
great...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900