LINQ Distinct, Except, Contains, Union, Intersect and IEqualityComparer

by Arnold Matusz 23 6 2009

LINQ is one feature I could not live without anymore. It is always a pain to work on projects using older technologies. The gap between .NET 1.1 (VS.NET 2003) and .NET 2.0 (VS.NET 2005) was huge and it was difficult to develop anything in ASP.NET v1.1 after you got your hands on .NET 2.0. But the gap between .NET 3.5 SP1 coupled with Visual Studio 2008 and the prior version is far bigger.

There is LINQ, LINQ to SQL, Lambda Expressions, the Entity Framework (and allot more) which simply boost your development speed. Anyone who hasn’t tried these yet: you definitely need to have a go! » Continue reading ...

LINQ to XML and LINQ to XML with XPath performance review

by Arnold Matusz 4 12 2008

In my post about LINQ to XML - XPath I've mentioned how Microsoft warns about the performance bottleneck when using LINQ to XML with the Extension class from the System.Linq.XPath namespace.

"There is some performance penalty for using these methods. Using LINQ to XML queries yields better performance. So it is only advisable to use such LINQ to XML with XPath queries if and only if your application won't suffer from the slight loss of performance!"
» Continue reading ...

LINQ Method cannot be translated into a store expression.

by Arnold Matusz 17 11 2008

LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.


This is a shortcomming of LINQ to Entities, and indeed the ADO.NET Entity Framework at the current release! The reason for a similar exception message is that in queries on the Entity Framework, custom methods and extensions methods cannot be translated into store expressions.

There are workarounds to still enjoy LINQ to Entities and as an example please read the following: » Continue reading ...

LINQ to XML - XPath

by Arnold Matusz 9 11 2008

LINQ to SQL may be dying these days, and to be frank that’s not a big deal as the Entity Framework is out which will 100% replace it. But LINQ as a concept is something new and won’t be out for some time!

While doing some configuration work I got into a sitation where I needed to query an XML file. Immediately my thoughts went to LINQ, and in term LINQ to XML. It is a great addition to the LINQ family but in terms of readability it’s far cry away from the old days when XPath was in use. » Continue reading ...

LINQ: OrderBy on multiple Fields

by Arnold Matusz 2 11 2008

Most people think that by calling OrderBy().OrderBy() will solves the problem of ordering a sequence by multiple fields. Well I'm dissapointed to announce this is not true because the second call overwrites the ordering clause specified in the first one!

First of all lets analyze the architecture of a LINQ ObjectQuery. The important peice is what it actually returns, namely: an IQueriable object! This IQueriable interface implements the IEnumarble interface which we are normally used to use when creating an ObjectQuery. » Continue reading ...

LINQ: Sequence contains no elements

by Arnold Matusz 28 10 2008

The InvalidOperationException: Sequence contains no elements exception is thrown whenever you try to retreive an element from an empty sequence. This generally happens when you call First on an empty sequence. What I think about for this situation is that I'ld need a method which would return null if the sequence is empty and the first object (maybe the only object) in the sequence otherwise.

In this case the call of FirstOrDefault is recomended. Although after a few searches I've found something similar: we could Single or SingleOrDefault instead of First. Calling these methods is almost exactly what First does except ... this will generate another exception if the sequest contains more elements: InvalidOperationException: Sequence contains more than one element. But the convenient factor is that it quietly returns the single element in a sequence, null of the sequence is empty and the above mentioned InvalidOperationException: Sequence contains more than one element. » Continue reading ...

About Arnold Matusz

Arnold Matusz

My name is Arnold Matusz. I'm a web developer specialized in .NET technologies with a passion for photography and cars.

View Arnold Matusz's profile on LinkedIn

Who's amung us