how to sort varchar column containing numeric values with linq lambdas to Entity

前端 未结 2 453
长发绾君心
长发绾君心 2021-01-14 06:22

I am using linq lambdas to query the MySql (Note MySql not Sql) with Entity Framwork in MVC. Now i have one table product one of column this table is pric

2条回答
  •  遥遥无期
    2021-01-14 06:46

    You can simulate fixed PadLeft in LINQ to Entities with the canonical function DbFunctions.Right like this

    instead of this

    a.price.PadLeft(10, '0')
    

    use this

    DbFunctions.Right("000000000" + a.price, 10)
    

    I haven't tested it with MySql provider, but canonical functions defined in the DbFunctions are supposed to be supported by any provider.

提交回复
热议问题