我在這裏堆棧我需要某人的幫助。我想從Refno相同Refno的不同表中獲取最大日期。 我現在的代碼給了我actionrecords表中存在的所有日期。如何從c#linq查詢表中選擇最大日期
我當前的代碼看起來像
public IQueryable<EmployerDetails> _employerProfileOverview(string refNo, string organisationname, string tradingname)
{
var query = (from _employerdetails in _entities.Organisations
join _lasttransaction in _entities.LevyTransactions on _employerdetails.Refno equals _lasttransaction.Refno
select new EmployerDetails
{
RefNo = _employerdetails.Refno,
Surname = _employerdetails.Surname,
TradingName = _employerdetails.TradingName,
Status = _employerdetails.Status,
TransactionDate = _lasttransaction.TransactionDate
});
if (string.IsNullOrEmpty(refNo).Equals(false))
query = query.Where(x => x.RefNo.Contains(refNo.Trim()));
if (string.IsNullOrEmpty(organisationname).Equals(false))
query = query.Where(x => x.Surname.Contains(organisationname.Trim()));
if (string.IsNullOrEmpty(tradingname).Equals(false))
query = query.Where(x => x.TradingName.Contains(tradingname.Trim()));
return query;
}
而我出來就把這個樣子
Refno TradingName Status TransactionDate
L940732953 PSG KONSULT BPK LICHTENBURG A 2011-01-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-03-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-04-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-05-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-06-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-07-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-08-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-09-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-10-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-11-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2012-12-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-01-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-02-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-03-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-04-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-05-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-05-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-06-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-11-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2013-12-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-01-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-02-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-03-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-04-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-05-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-06-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-07-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-08-01 00:00:00.00
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-09-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-10-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-11-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2014-12-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2015-01-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2015-02-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2015-03-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2015-04-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2015-05-01 00:00:00.000
L940732953 PSG KONSULT BPK LICHTENBURG A 2015-06-01 00:00:00.000
L940733035 BROUGHTON AND JONCK A 2011-05-01 00:00:00.000
L940733035 BROUGHTON AND JONCK A 2011-05-01 00:00:00.000
L940733035 BROUGHTON AND JONCK A 2011-05-01 00:00:00.000
L940733035 BROUGHTON AND JONCK A 2011-05-01 00:00:00.000
L940733035 BROUGHTON AND JONCK A 2011-05-01 00:00:00.000
L940733035 BROUGHTON AND JONCK A 2011-05-01 00:00:00.000
L940736574 COVERS FOODS CC Y 2011-03-01 00:00:00.000
L940736574 COVERS FOODS CC Y 2011-03-01 00:00:00.000
L940736574 COVERS FOODS CC Y 2011-05-01 00:00:00.000
L940736574 COVERS FOODS CC Y 2011-05-01 00:00:00.000
L940738141 TEAMWORX SHOPFITTERS (PTY) LTD A 2011-01-01 00:00:00.000
L940738141 TEAMWORX SHOPFITTERS (PTY) LTD A 2011-02-01 00:00:00.000
L940738141 TEAMWORX SHOPFITTERS (PTY) LTD A 2011-02-01 00:00:00.000
L940738141 TEAMWORX SHOPFITTERS (PTY) LTD A 2011-04-01 00:00:00.000
L940738141 TEAMWORX SHOPFITTERS (PTY) LTD A 2011-05-01 00:00:00.000
我只是想顯示最大(交易)僅在每次每Personal Data個人紀錄。
請幫幫我吧。