Ehsan Akbar Ehsan Akbar - 2 months ago 16
C# Question

sort number and alphabet string using EF

I have a column with `string type in my database that contains these value :

410
AFP-EXEC
412
411
AFP-EXEP


So i want to sort them as you can see :

_materialIssueVoucherRepository.Get().OrderBy(i=>int.Parse(i.Code)).ToList()


But it returns an obvious error
Convert error string to int
,The result should be like this :

410
411
412
AFP-EXEC
AFP-EXEP


The Alphabet part is not important,Can i do that in EF?

Answer
int temp;
_materialIssueVoucherRepository
        .Get()
        .OrderBy(i => int.TryParse(i.Code, out temp) ? temp : int.MaxValue)
        .ToList()
Comments