LINQ: Dot Notation vs Query Expression
- by Martín Marconcini
I am beginning to use LINQ in general (so far toXML and toSQL). I've seen that sometimes there are two or more ways to achieve the same results. Take this simple example, as far as I understand both return exactly the same thing:
SomeDataContext dc = new SomeDataContext();
var queue = from q in dc.SomeTable
where q.SomeDate <= DateTime.Now && q.Locked != true
orderby (q.Priority, q.TimeCreated)
select q;
var queue2 = dc.SomeTable
.Where( q => q.SomeDate <= DateTime.Now && q.Locked != true )
.OrderBy(q => q.Priority)
.ThenBy(q => q.TimeCreated);
Besides any mistake I may have made in the syntax or a missing parameter or difference, the idea is that there are two ways to express the same thing; I understand that the first method has some limitations and that the "dot notation" is more complete, but besides that, are there any other advantages?