要编写一个LINQ以添加两个记录,并在表中从中减去一条记录 [英] To write a LINQ for adding two records subtracting a record from it in the table

查看:97
本文介绍了要编写一个LINQ以添加两个记录,并在表中从中减去一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是Linq的新手,我的问题是我有这个公式来找到净佣金= NB +续订回扣;我的数据库中有NB,Renewal,Clawback值.我要做的就是计算净佣金.

我必须在LINQ中执行此操作.但它没有得到正确的结果.我已经为上述记录编写了SQL查询,即

Hi,
i am new to Linq.My problem is i have this formula to find the net commission=NB+Renewal-clawback ; i am having NB,Renewal,Clawback values in my data base.all i need to do is calculate the net commission.

I have to do this in LINQ. but its not coming the correct result. I have written the SQL query for the above records ie

SELECT  COMMISSIONSPAIDDATE,(SUM(CommissionAmount) +(SELECT TAB1.CommissionAmount FROM (SELECT     COMMISSIONSPAIDDATE,PaymentType, SUM(CommissionAmount) AS CommissionAmount FROM  tblCommissionStatus WHERE (PaymentType = '113') GROUP BY PaymentType,COMMISSIONSPAIDDATE) TAB1)-(SELECT TAB1.CommissionAmount FROM (SELECT     COMMISSIONSPAIDDATE,PaymentType, SUM(CommissionAmount) AS CommissionAmount FROM  tblCommissionStatus WHERE (PaymentType = '115') GROUP BY PaymentType,COMMISSIONSPAIDDATE) TAB1)) AS NETCOMMISSION FROM tblCommissionStatus WHERE (PaymentType = '111') GROUP BY PaymentType,COMMISSIONSPAIDDATE




请帮我为上述SQL编写LINQ.这将是真正的巨大帮助.
谢谢




Pls help me to write the LINQ for the above SQL. It will be a real great help.
Thanks

推荐答案

我不确定我是否正确理解了您的描述-特别是,对数据库中具有哪些表/列以及它们所代表的内容进行一些描述会有所帮助.

但是,如果您只是尝试对每条记录进行简单的计算,则类似以下内容的方法将起作用.

您需要设置数据上下文和实体(只需在VS设计器中拖放,然后在属性"窗格中对相关位进行一些重命名即可).然后,请参见下面的代码.

如果您的数据结构不同,请发布数据结构的详细信息,然后我将看到如何修改代码.

I'' not sure I understand your description correctly - in particular, some description of what tables / columns you have in your database and what they represent would help.

But if you are just trying to do a straightforward calculation on each record, something like the following would work.

You need to set up your data context and entities (drag and drop in the VS designer and then do a bit of renaming of relevant bits in the Properties pane is all you need). Then see code below.

If your data structure is different, post details of the data structure and I''ll see what I can do to amend the code.

IEnumerable<MyCommissionStatus> MyCommissionStatuses =
(from ACommissionStatus in MyDC.CommissionStatuses
where // [add whatever you need here]
select ACommissionStatus);

foreach(MyCommissionStatus ACommissionStatus in MyCommissionStatuses)
{
    ACommissionStatus.commission = ACommissionStatus.NB + ACommissionStatus.Renewal - ACommissionStatus.clawback;
}

MyDC.SubmitChanges();



您可能还需要考虑事务/失败模式等-但以上内容提供了基础知识.



You might also want to think about transactions / failure modes etc. - but the above gives the basics.


这篇关于要编写一个LINQ以添加两个记录,并在表中从中减去一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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