Mixing Linq queries and Linq lambdas I have been given a change to rewrite an old framework we use, and to implement the repository and unit of work patterns, but in an attempt to not rewriting all queries I have ended up with a weird combination of Linq queries and Linq lambdas.

I was hoping someone could explain to me a better way of doing this, or advice what to do.

First off, the generic repository has a method Get() defined as

public virtual IEnumerable&lt;TEntity&gt; Get(
Expression&lt;Func&lt;TEntity, bool&gt;&gt; filter = null,
Func&lt;IQueryable&lt;TEntity&gt;, IOrderedQueryable&lt;TEntity&gt;&gt; orderBy = null,
string includeProperties = "")


and the old code would use a context directly like this:

Arrival arrival =
    (from a in DataContextPortX.Arrival
         where a.I_ARRIVALNO == arrivalNo
     select a).SingleOrDefault();


And now, since the class no longer has direct access to the context I can choose to keep the old code with the Get() method mixed in like this:

Arrival arrival =
    (from a in Get()
        where a.I_ARRIVALNO == arrivalNo
        select a).SingleOrDefault();


or I can rewrite the whole query to lambda like this:

var arrival = Get(a =&gt; a.I_ARRIVALNO == arrivalNo).SingleOrDefault();


I would of course prefer to rewrite all queries but there are a lot of them, and this was the shortest I could find, others are like really long.

But I am worried about first using Get() and then iterating of that, but for all I know it doesn't matter.
There is a reason why you can write LINQ queries using the query syntax or the method syntax: sometimes one is better and sometimes it's the other one.

So, when you're writing a new query, use the syntax that suits your query better. This usually means method syntax for simpler queries (especially if they're as simple as your example) and query syntax for more complicated queries (especially ones with multiple sources).

When you need to use an operator that's only available in method syntax (like SingleOrDefault()), I think that points towards using method syntax for the whole query. But using both syntaxes in the same query can sometimes make sense too.

When it comes to rewriting old code: if it works and it's reasonably readable, I would leave it be, I think the effort spent rewriting it isn't worth it.