C# - Return record which has the lowest PayDate but also the highest ReconciliationDate [duplicate]












0
















This question already has an answer here:




  • LINQ OrderBy with more than one field

    6 answers




So I need to pull the record which matches the following criteria:



A record which has the lowest PayDate but also the highest ReconciliationDate.
An example of records can be seen like this



public class Data {
public string Name { get; set; }
public DateTime PayDate { get; set; }
public DateTime ReconciliationDate { get; set; }
}

--------------------------------------------------
| Name | PayDate | ReconciliationDate |
--------------------------------------------------
| Andrew | 11/14/2018 | 07/01/2018 |
--------------------------------------------------
| Andrew | 10/14/2018 | 06/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 08/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 03/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 10/01/2018 |


So the correct record to be returned would be #5



How can I achieve this using C#?



I have this so far:



    var recordsNextCouponPaymentAfterLastOfMonth = externalInterestForSecurity.Where(aExternalRecord => aExternalRecord.PayDate > priorMonthEnd);









share|improve this question













marked as duplicate by Camilo Terevinto c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 22:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • You could sort the list with OrderBy, OrderByDescending, ThenBy, and/or ThenByDescending, then take the first row. See this question.

    – John Wu
    Nov 14 '18 at 22:38


















0
















This question already has an answer here:




  • LINQ OrderBy with more than one field

    6 answers




So I need to pull the record which matches the following criteria:



A record which has the lowest PayDate but also the highest ReconciliationDate.
An example of records can be seen like this



public class Data {
public string Name { get; set; }
public DateTime PayDate { get; set; }
public DateTime ReconciliationDate { get; set; }
}

--------------------------------------------------
| Name | PayDate | ReconciliationDate |
--------------------------------------------------
| Andrew | 11/14/2018 | 07/01/2018 |
--------------------------------------------------
| Andrew | 10/14/2018 | 06/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 08/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 03/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 10/01/2018 |


So the correct record to be returned would be #5



How can I achieve this using C#?



I have this so far:



    var recordsNextCouponPaymentAfterLastOfMonth = externalInterestForSecurity.Where(aExternalRecord => aExternalRecord.PayDate > priorMonthEnd);









share|improve this question













marked as duplicate by Camilo Terevinto c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 22:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • You could sort the list with OrderBy, OrderByDescending, ThenBy, and/or ThenByDescending, then take the first row. See this question.

    – John Wu
    Nov 14 '18 at 22:38
















0












0








0









This question already has an answer here:




  • LINQ OrderBy with more than one field

    6 answers




So I need to pull the record which matches the following criteria:



A record which has the lowest PayDate but also the highest ReconciliationDate.
An example of records can be seen like this



public class Data {
public string Name { get; set; }
public DateTime PayDate { get; set; }
public DateTime ReconciliationDate { get; set; }
}

--------------------------------------------------
| Name | PayDate | ReconciliationDate |
--------------------------------------------------
| Andrew | 11/14/2018 | 07/01/2018 |
--------------------------------------------------
| Andrew | 10/14/2018 | 06/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 08/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 03/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 10/01/2018 |


So the correct record to be returned would be #5



How can I achieve this using C#?



I have this so far:



    var recordsNextCouponPaymentAfterLastOfMonth = externalInterestForSecurity.Where(aExternalRecord => aExternalRecord.PayDate > priorMonthEnd);









share|improve this question















This question already has an answer here:




  • LINQ OrderBy with more than one field

    6 answers




So I need to pull the record which matches the following criteria:



A record which has the lowest PayDate but also the highest ReconciliationDate.
An example of records can be seen like this



public class Data {
public string Name { get; set; }
public DateTime PayDate { get; set; }
public DateTime ReconciliationDate { get; set; }
}

--------------------------------------------------
| Name | PayDate | ReconciliationDate |
--------------------------------------------------
| Andrew | 11/14/2018 | 07/01/2018 |
--------------------------------------------------
| Andrew | 10/14/2018 | 06/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 08/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 03/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 10/01/2018 |


So the correct record to be returned would be #5



How can I achieve this using C#?



I have this so far:



    var recordsNextCouponPaymentAfterLastOfMonth = externalInterestForSecurity.Where(aExternalRecord => aExternalRecord.PayDate > priorMonthEnd);




This question already has an answer here:




  • LINQ OrderBy with more than one field

    6 answers








c# linq






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 22:32









AndrewAndrew

346318




346318




marked as duplicate by Camilo Terevinto c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 22:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Camilo Terevinto c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 22:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • You could sort the list with OrderBy, OrderByDescending, ThenBy, and/or ThenByDescending, then take the first row. See this question.

    – John Wu
    Nov 14 '18 at 22:38





















  • You could sort the list with OrderBy, OrderByDescending, ThenBy, and/or ThenByDescending, then take the first row. See this question.

    – John Wu
    Nov 14 '18 at 22:38



















You could sort the list with OrderBy, OrderByDescending, ThenBy, and/or ThenByDescending, then take the first row. See this question.

– John Wu
Nov 14 '18 at 22:38







You could sort the list with OrderBy, OrderByDescending, ThenBy, and/or ThenByDescending, then take the first row. See this question.

– John Wu
Nov 14 '18 at 22:38














1 Answer
1






active

oldest

votes


















0














You are looking for the LINQ methods OrderBy and ThenBy



In your case its



.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First





share|improve this answer


























  • Select first one I think

    – Andrew
    Nov 14 '18 at 22:44











  • @CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

    – DevEstacion
    Nov 14 '18 at 22:44


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You are looking for the LINQ methods OrderBy and ThenBy



In your case its



.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First





share|improve this answer


























  • Select first one I think

    – Andrew
    Nov 14 '18 at 22:44











  • @CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

    – DevEstacion
    Nov 14 '18 at 22:44
















0














You are looking for the LINQ methods OrderBy and ThenBy



In your case its



.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First





share|improve this answer


























  • Select first one I think

    – Andrew
    Nov 14 '18 at 22:44











  • @CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

    – DevEstacion
    Nov 14 '18 at 22:44














0












0








0







You are looking for the LINQ methods OrderBy and ThenBy



In your case its



.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First





share|improve this answer















You are looking for the LINQ methods OrderBy and ThenBy



In your case its



.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 22:45

























answered Nov 14 '18 at 22:39









DevEstacionDevEstacion

1,58711024




1,58711024













  • Select first one I think

    – Andrew
    Nov 14 '18 at 22:44











  • @CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

    – DevEstacion
    Nov 14 '18 at 22:44



















  • Select first one I think

    – Andrew
    Nov 14 '18 at 22:44











  • @CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

    – DevEstacion
    Nov 14 '18 at 22:44

















Select first one I think

– Andrew
Nov 14 '18 at 22:44





Select first one I think

– Andrew
Nov 14 '18 at 22:44













@CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

– DevEstacion
Nov 14 '18 at 22:44





@CamiloTerevinto what do you mean half the answer? it's exactly what he needs.

– DevEstacion
Nov 14 '18 at 22:44





Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma