在linq查询asp.net中将字符串转换为十进制 [英] converting string into decimal in sum linq query asp.net

查看:82
本文介绍了在linq查询asp.net中将字符串转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用实体查询从我的数据库表中获取一些数据的总和



i am trying to get the sum of some data from my database table using Entity Query

public List<total> gettotal(int apid)
    {
        var query = (from a in DB.TblApplicantInstallments
                     where
                         a.ApplicantId == apid
                     group a by a.ApplicantId into g
                     select new total()
                         {
                             paidtotal = g.Where(x => x.Status == "Paid").Sum(x =>decimal.Parse(x.InstallmentDueAmount)),
                            unpaidtoal = g.Where(x => x.Status == "Not Paid").Sum(x => (decimal)x.InstallmentDueAmount)

                         }).ToList();
        List<total> list = query.ToList();
        return list;
           }
}
public class total
{
    public decimal? paidtotal { get; set; }
    public decimal? unpaidtoal { get; set; }
}



但我收到以下错误:

LINQ to Entities无法识别方法' System.Decimal Parse(System.String)

请告诉我我的代码有什么问题?

提前谢谢


but i am getting the following error:
LINQ to Entities does not recognize the method 'System.Decimal Parse(System.String)
please tell me what is wrong with my code?
Thanks in advance

推荐答案

LINQ to Entites从你的代码构建一个SQL语句...它也不知道如何处理该Parse部分,因为它无法转换为SQL ...

什么该列的SQL类型?你确定需要转换吗?我的直觉说这也是SQL中的一个数值,所以你把它变成.NET十进制的所有努力都是不必要的......
LINQ to Entites builds an SQL statement from your code...It do nor know what to do with that Parse part as it can not be converted to SQL...
What the SQL type of that column? Are you sure you need to convert it? My intuition says that is is a numeric value in SQL too, so all your effort to make it into .NET decimal is needless...


这篇关于在linq查询asp.net中将字符串转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆