Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XML Anonymous Types
Message
From
28/03/2017 05:44:25
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows Server 2016
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01649231
Message ID:
01649426
Views:
30
>Doesn't take care of if for me :-{
>If FirstOrDefault() returns null than trying to access any property of the expected type throws a NullReferenceException

Strange, maybe it doesn't where you tried? In Linq To SQL it works (internally creates a coalesce query):
void Main()
{
	var data = from c in Customers
			   let first = c.Orders.FirstOrDefault()
			   let firstDet = first.OrderDetails.FirstOrDefault()
			   select new {
			      Customer = c.CustomerID,
				  City = first.ShipCity ?? "",
				  EmployeeFirst = first.Employee.FirstName ?? "",
				  OrderDetailFirst = firstDet.Product.ProductName ?? ""
				  
			   };
	data.Dump(); // LinqPad luxury
}
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform