Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below is my code for selecting string list of column for loanmasters :-

C#
var loan = context.loanmasters.Where(m => m.MemberUniqueId == emberUniqueId).Select(
m => new List<String> {

               m.LoanAccountNo.ToString(),
               m.StartDate.ToString(),
               m.Tenure.ToString(),
               m.OutstandingPrinciple.ToString(),
               m.InterestRate.ToString(),
               m.LoanAmount.ToString(),
               m.EMI.ToString()
               });

but i get column values in unexpected sequence which is below : =

var dsLoans = [["84","62423","9","2010054802","250000","19/11/2011","3000"]];



that suppose to be like below :-
var dsLoans = [["2010054802","19/11/2011","84","62423","9","250000","3000"]];


What I have tried:

compared with my another working code but did not find any things.
Posted
Updated 19-Dec-16 6:47am
Comments
Richard Deeming 13-Dec-16 12:29pm    
A List<T> will not reorder the items you add to it. There must be something else going on.

Debug your code and examine the loan variable immediately after the statement you've shown. Then step through your code to find out where the list is being reordered.
jayeshkumar.rathod 13-Dec-16 12:39pm    
please copy and paste in new tab.. for debug image.

https://s27.postimg.org/z0n2y22ar/Sequence_Not_Coming_accourding_select.png
Richard Deeming 13-Dec-16 14:50pm    
That's very odd. And you've verified that the columns on the m object contain the values you're expecting?

I'd normally expect to see an extra level in the tool-tip, since the variable is an IEnumerable<List<String>> - is that a pinned data tip?
jayeshkumar.rathod 14-Dec-16 0:00am    
yes.. richard
Matthew Dennis 14-Dec-16 11:36am    
Why use a List<String>? How about just creating an anonymous object with the properties you want, or even use a class with the properties you want?

Thanks to all for all your precious time.

i got solution by using below code :-
C#
var loan = context.loanmasters.Where(m => m.MemberUniqueId == MemberUniqueId).Select(m => new
                       {
                           LoanAccountNo = m.LoanAccountNo.ToString(),
                           StartDate = m.StartDate.ToString(),
                           Tenure = m.Tenure.ToString(),
                           OutstandingPrinciple = m.OutstandingPrinciple.ToString(),
                           InterestRate = m.InterestRate.ToString(),
                           LoanAmount = m.LoanAmount.ToString(),
                           EMI = m.EMI.ToString()
                       });

               var listOfLoanStringLists = new L.List<String[]>();
               foreach (var loanRec in loan)
               {
                   listOfLoanStringLists.Add(new String[] { loanRec.LoanAccountNo, loanRec.StartDate, loanRec.Tenure, loanRec.OutstandingPrinciple, loanRec.InterestRate, loanRec.LoanAmount, loanRec.EMI });
               }

               ViewBag.LoanMaster = JsonConvert.SerializeObject(listOfLoanStringLists);
 
Share this answer
 
did you try the alias in it
i think it can solve your problem

try it and then inform me
i will again research your problem if it is not working
 
Share this answer
 
Comments
jayeshkumar.rathod 13-Dec-16 12:32pm    
can you please give alias example for one column .. ?
Member 12216380 14-Dec-16 13:55pm    
var providers = EMRRepository.GetProviders().Select(x => new { Name = x });

try this method

it may be helpful to you

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