Geeks With Blogs

@azamsharp
  • azamsharp The WWDC app says that there are new videos but there is nothing under videos!!! about 316 days ago
  • azamsharp Can I post my opinion on iOS 7 Beta or is it under NDA or something? about 316 days ago
  • azamsharp iOS 7 BETA installed successfully! about 316 days ago
  • azamsharp iOS 7 BETA installed! Now restoring! I am on NET10 which uses AT&T network. Hopefully 3G will still work! Lets c.. about 316 days ago
  • azamsharp The missing of button borders in Xcode 5 makes it hard to determine the clickable area. about 316 days ago
  • azamsharp I might wait for iOS to be released before I can put it on my device! Don't want a bricked or unstable device! about 316 days ago
  • azamsharp Android has many features that no one uses, number of versions that no one upgrades to and thousands of apps that no one pays for. about 316 days ago
  • azamsharp Maybe it is just me but the new iOS 7 UI looks like Windows Phone 8 UI! #maybeIamCrazy about 317 days ago
  • azamsharp Anyone using H20 network upgraded to iOS 7 BETA Keep me updated if you face any problems. about 317 days ago
  • azamsharp @merowing_ You already downloaded it! I cannot even load the developer's website! :( about 317 days ago

AzamSharp Some day I will know everything. I hope that day never comes.

Suppose you have a tblRoom and tblUserInfo. Now, you need to select all the rooms regardless of whether the room has user information or not. This calls for a LEFT JOIN which will select everything from the LEFT side (the room side) regardless of the join on the right side. Here is the example.

 var list = from r in dc.tblRooms
                           join ui in dc.tblUserInfos
                           on r.UserName equals ui.UserName into userrooms
                           where r.CourseID == 1848

                           from ur in userrooms.DefaultIfEmpty()

                           select new
                           {
                               FirstName = (ur.FirstName == null) ? "N/A" : ur.FirstName,
                               LastName = (ur.LastName == null) ? "N/A" : ur.LastName,
                               RoomName = r.Name
                              
                           };

The anonymous type replaces the "null" FirstName and LastName with "N/A" (not available).

Posted on Monday, April 7, 2008 7:45 AM | Back to top


Comments on this post: LEFT JOINS and DefaultIfEmpty Operator in LINQ

# re: LEFT JOINS and DefaultIfEmpty Operator in LINQ
Requesting Gravatar...
You should be able to simplify this even further with "??" operator...

var list =
from r in dc.tblRooms
join ui in dc.tblUserInfos
on r.UserName equals ui.UserName into userrooms
where r.CourseID == 1848
from ur in userrooms.DefaultIfEmpty()
select new
{
FirstName = (ur.FirstName ?? "N/A",
LastName = (ur.LastName ?? "N/A",
RoomName = r.Name
};
Left by The Wolf on Apr 07, 2008 7:53 AM

# re: LEFT JOINS and DefaultIfEmpty Operator in LINQ
Requesting Gravatar...
Ahh! yes.

Thanks!
Left by Mohammad Azam on Apr 07, 2008 8:33 AM

Your comment:
 (will show your gravatar)
 


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net | Join free