最近6次付款 [英] Last 6 Payments

查看:169
本文介绍了最近6次付款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从仅由一个组成的模式中获取最后六笔付款

I need to get the last six payments from a schema that consists of just

贡献ID 到期日 金额

Contribution Id DUE Date Amount

付款分散了7年,我只需要获得最新的最近六次付款,因为我认为这样做会遵循我的sql

The payments spread over 7 years and I need to get the most current last six payments only I thought this would do it it as it follows my sql

SELECT TOP 6 [ID]
  ,[customerInfo]
  ,[IVACODE]
  ,[Contribution]
  ,[DUE_DATE]
  ,[isActive]
  ,[isDeleted]
FROM [portal].[dbo].[tblPortalContributionSchedule]
where customerInfo='01F6B68B-6FC2-4F9D-B586-6934B8D6C979'
and DUE_DATE <='2016/09/26' 
ORDER BY DUE_DATE DESC

Linq版本

List<tblPortalContributionSchedule> _contributions 
    = portalEntities.tblPortalContributionSchedules
            .Where(a => a.customerInfo == _customerId 
                        && a.isDeleted == false 
                        && a.DUE_DATE <=Convert.ToDateTime("2016/09/26"))
            .Take(6)
            .OrderByDescending(o => o.DUE_DATE)
            .ToList();

foreach (var contribution in _contributions)
{

            AllPayments.Add(new Payments(contribution.ID, Convert.ToDecimal(contribution.Contribution), Convert.ToDateTime(contribution.DUE_DATE), false));

}

但其产生的结果与下面的结果不同

But its not producing the same results as per below

对不起,我需要用linq回答,我不需要的是,我做得到的正确方法比预期的要少

Sorry people i require the answer in linq i need to no is that the correct way of doing it i getting less than exepected

编辑1 这是我到目前为止的查询,但仍然无法获得与sql脚本相同的结果

Edit 1 This is the query I have so far but I still am not getting the same results as my sql script

 List<tblPortalContributionSchedule> _contributions = 
portalEntities.tblPortalContributionSchedules.Where(a => a.customerInfo == 
_customerId && a.isDeleted == false && a.DUE_DATE 
<=Convert.ToDateTime("2016/09/26")).OrderByDescending(o => 
o.DUE_DATE).Take(6).ToList();

编辑2
展示我在视频中显示的代码

Edit 2
To show the code that I showed in the video

    public List<Payments> getAllPayments(Guid _customerId)

    {
        List<Payments> AllPayments = new List<Payments>();

        List<tblPortalPayment> _payments = portalEntities.tblPortalPayments.Where(a => a.CustomerId == _customerId && a.isDeleted == false).ToList();

        foreach (var payment in _payments)
        {
            AllPayments.Add(new Payments(payment.id, Convert.ToDecimal(payment.paymentDue), Convert.ToDateTime(payment.paymentDate), Convert.ToBoolean(payment.isinArrears)));

        }

  List<tblPortalContributionSchedule> _contributions = portalEntities.tblPortalContributionSchedules.Where(a => a.customerInfo == _customerId && a.isDeleted == false && a.DUE_DATE<= Convert.ToDateTime("2016/09/26")).OrderByDescending(o => o.DUE_DATE).Take(6).ToList();
        foreach (var contribution in _contributions)
        {

            AllPayments.Add(new Payments(contribution.ID, Convert.ToDecimal(contribution.Contribution), Convert.ToDateTime(contribution.DUE_DATE), false));

        }


        var result = AllPayments.OrderByDescending(o => o.paymentDate).ToList(); 

        return AllPayments.OrderByDescending(o => o.paymentDate).ToList();

    }      

推荐答案

您可以尝试如下所示,并让我们知道结果.

You can try it as shown below and let us know the result.

var dueDateFilter = new DateTime(2016, 09, 26);

List<tblPortalContributionSchedule> _contributions = 
    portalEntities.tblPortalContributionSchedules
        .Where(a => a.customerInfo == _customerId 
            && a.isDeleted == false 
            && a.DUE_DATE <= dueDateFilter)
        .OrderByDescending(o => o.DUE_DATE)
        .Take(6)
        .ToList();

这篇关于最近6次付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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