Thursday, October 1, 2009

Linq with Outer Join, Ternary and orderby with linq

var query = from lfp in db.LogFundingPrograms
join rc in db.RefCycles on lfp.CycleId equals rc.CycleId
into JoinedRc
from rc in JoinedRc.DefaultIfEmpty()
join rf in db.RefFrequencies on lfp.Frequency equals rf.FrequencyId
orderby lfp.LogFundingId descending
select new
{
lfp.LogFundingId,
lfp.LogActionId,
lfp.FundingId,
lfp.FundingCode,
lfp.InstrumentCode,
LogActionDescription = lfp.RefLogAction.Description,
lfp.ApplicableDate,
lfp.Description,
rf.Frequency,
lfp.RollOverDay,
CycleDesc = lfp.CycleId != null ? rc.CycleDesc : "",
lfp.CCY,
lfp.CycleId,
lfp.IsConfirmed,
lfp.LastUser,
lfp.LastModified
};

as you can see the CycleDesc comes with a empty string if the CycleId doesn't bring a value since can be null.

No comments: