Guy Barrette, Microsoft, Regional Director, Montreal, Canada, Visual Studio, .NET Expertise LINQ to SQL: Returning Complex Objects (Performance Problems?) - Guy Barrette

Guy Barrette

Microsoft Regional Director, Montreal, Canada

LINQ to SQL: Returning Complex Objects (Performance Problems?)

In my previous post, one reader commented that the proposed LINQ query would be utterly slow so I did a quick unscientific showdown.

In the left corner: the query returning complex objects from anonymous types:
var q = from o in ctx.Orders
        where o.CustomerID == id
        select new { Detail = o.Order_Details, CustomerID = o.CustomerID, OrderDate = o.OrderDate, OrderID = o.OrderID, ShippedDate = o.ShippedDate, ShipCity = o.ShipCity };

In the right corner: the query returning complex objects from POCOs:
var q = from o in ctx.Orders
where o.CustomerID == id
select new TransportObjects.Northwind.Order {
Detail = o.Order_Details.Select(item => new  TransportObjects.Northwind.OrderDetail {
ProductID = item.ProductID 
}).ToArray(),
CustomerID = o.CustomerID, OrderDate = o.OrderDate, OrderID = o.OrderID, ShippedDate = o.ShippedDate, ShipCity = o.ShipCity};

The weapons: 50,000 orders each having 10 order details rows meaning 500,000 objects.

The result: it's a tie!

Yep, both queries returned the results in about 2 seconds using SQL Server Express 2005 locally (no layers, no WCF etc)

 

Posted: Apr 06 2008, 08:41 PM by guybarrette | with 1 comment(s)
Filed under:

Comments

kenny.no said:

*Phew*

# April 7, 2008 12:51 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)