Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drawbacks of linq

Tags:

linq

What are the drawbacks of linq in general.

like image 787
user99792 Avatar asked Dec 30 '22 01:12

user99792


2 Answers

  • Can be hard to understand when you first start out with it
  • Deferred execution can separate errors from their causes (in terms of time)
  • Out-of-process LINQ (e.g. LINQ to SQL) will always be a somewhat leaky abstraction - you need to know what works and what doesn't, essentially

I still love LINQ massively though :)

EDIT: Having written this short list, I remembered that I've got an answer to a very similar question...

like image 139
Jon Skeet Avatar answered Jan 01 '23 16:01

Jon Skeet


The biggest pain with LINQ is that (with database backends) you can't use it over a repository interface without it being a leaky abstraction.

LINQ is fantastic within a layer (especially the DAL etc), but since different providers support different things, you can't rely on Expression<Func<...>> or IQueryable<T> features working the same for different implementations.

As examples, between LINQ-to-SQL and Entity Framework:

  • EF doesn't support Single()
  • EF will error if you Skip/Take/First without an explicit OrderBy
  • EF doesn't support UDFs

etc. The LINQ provider for ADO.NET Data Services supports different combinations. This makes mocking and other abstractions unsafe.

But: for in-memory (LINQ-to-Objects), or in a single layer/implementation... fantastic.

Some more thoughts here: Pragmatic LINQ.

like image 41
Marc Gravell Avatar answered Jan 01 '23 16:01

Marc Gravell