Created
May 12, 2011 12:39
-
-
Save linuxbender/968418 to your computer and use it in GitHub Desktop.
Linq and C# - Join example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long tblUnitID = 808; | |
var _rec = (from u in _db.tblUnits | |
join ut in _db.tblUnitTypes on u.tblUnitTypeID equals ut.tblUnitTypeID into gj | |
from subset in gj.DefaultIfEmpty() | |
where u.tblUnitID == tblUnitID | |
select new { u.tblUnitID, u.tblUnitName, u.tblUnitTypeID, tblUnitTypeName = (subset == null ? String.Empty : subset.tblUnitTypeName) }).FirstOrDefault(); | |
Console.WriteLine("{0} {1} {2} {3}",_rec.tblUnitID, _rec.tblUnitName, _rec.tblUnitTypeID, _rec.tblUnitTypeName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment