Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq to entities orderby

How can I convert this query to linq to entities with entity framework:

SELECT  customer_id,
    customer_name,
    customer_code
FROM dbo.V_STF_CUSTOMER
WHERE   company_id=@company_id AND
ORDER BY    CASE
            WHEN ISNUMERIC(customer_name)=1 THEN 1
            ELSE 0
        END,
        customer_name

I have this:

return CUstomers.GetQuery().
            Where(x => x.CompanyId == companyId).
        OrderBy(??This is my problem??);

I don't know how to translate the orderby. Any idea?

like image 616
Naor Avatar asked Jan 20 '23 16:01

Naor


1 Answers

return Customers.GetQuery().
            Where(x => x.CompanyId == companyId).
        OrderBy(x=> SqlFunctions.IsNumeric(x.customer_name)).
        ThenBy(x=> x.customer_name);
like image 55
Oskar Kjellin Avatar answered Jan 28 '23 07:01

Oskar Kjellin