LINQ to Entities string to decimal a column

前端 未结 2 883
别跟我提以往
别跟我提以往 2021-01-19 04:19

I have researched this question to death. Everyone and their brother wants to know how to convert an int or decimal to string, but I can\'t find any example of doing the op

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 04:53

    You have to get the data to a List first and after that you can cast whatever you want.

    var orders = 
        from s in
            ((from o in db.Orders
            where o.Order_Complete
            select o).ToList())
        select new { 
            s.Order_Id, 
            s.MySEL_Name, 
            s.MySEL_EMail, 
            s.MySEL_Bus_Name,
            Double.Parse(s.Total_Amt),
            s.Order_Complete_DateTime
        };
    

    I think the EMS way would look much better in your code ;)

    var orders =
        db.Orders.Where(s => s.Order_Complete).ToList().Select(s => new { /*...*/ }
    

    After casting ToList() you have got the data object based and can modify it, if you don't you can use Double.Parse because EF is trying to find e.g. a stored procedure on the database and will throw an exception.

提交回复
热议问题