Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XML Anonymous Types
Message
De
28/03/2017 05:44:25
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/03/2017 10:07:08
Information générale
Forum:
ASP.NET
Catégorie:
XML
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Network:
Windows Server 2016
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01649231
Message ID:
01649426
Vues:
31
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform