C# - Return record which has the lowest PayDate but also the highest ReconciliationDate [duplicate]
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);
c# linq
marked as duplicate by Camilo Terevinto
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.
add a comment |
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);
c# linq
marked as duplicate by Camilo Terevinto
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 withOrderBy
,OrderByDescending
,ThenBy
, and/orThenByDescending
, then take the first row. See this question.
– John Wu
Nov 14 '18 at 22:38
add a comment |
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);
c# linq
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
c# linq
asked Nov 14 '18 at 22:32
AndrewAndrew
346318
346318
marked as duplicate by Camilo Terevinto
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
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 withOrderBy
,OrderByDescending
,ThenBy
, and/orThenByDescending
, then take the first row. See this question.
– John Wu
Nov 14 '18 at 22:38
add a comment |
You could sort the list withOrderBy
,OrderByDescending
,ThenBy
, and/orThenByDescending
, 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
add a comment |
1 Answer
1
active
oldest
votes
You are looking for the LINQ methods OrderBy
and ThenBy
In your case its
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are looking for the LINQ methods OrderBy
and ThenBy
In your case its
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First
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
add a comment |
You are looking for the LINQ methods OrderBy
and ThenBy
In your case its
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First
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
add a comment |
You are looking for the LINQ methods OrderBy
and ThenBy
In your case its
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First
You are looking for the LINQ methods OrderBy
and ThenBy
In your case its
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First
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
add a comment |
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
add a comment |
You could sort the list with
OrderBy
,OrderByDescending
,ThenBy
, and/orThenByDescending
, then take the first row. See this question.– John Wu
Nov 14 '18 at 22:38