Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ or ADO.net Entity Framework - which to learn?

A bit of a clarification: I was browsing Julia Lerman's Oreilly title on Entity framework and I got mighty confused.

I have Charlie Calvert's essential LINQ, but from my 10 minute session with Lerman's book, it transpires that LINQ is LINQ to SQL which seems underpowered with its DataContext object etc...

Whereas Entity Framework is the future, but it has something called Entity SQL which to my eye looked exactly like Transact-SQL. Now my eye could be a bit rusty, but the question is:

Since Entity Framework is the main horse that Microsoft is backing, is there any point in learning LINQ to SQL with its

        var numberGroups =
            from n in numbers
            group n by n % 5 into g
            select new { Remainder = g.Key, Numbers = g };

And am I confused in thinking that Entity SQL and LINQ are two different technologies, does entity SQL in fact use LINQ?

post the many replies I got:

Ok Folks, I'm new to this, so I'm editing my answer this time ;-) Many thanks for your full, expedited and very helpful answers. Regards MereMortal

like image 711
MereMortal Avatar asked May 14 '09 22:05

MereMortal


4 Answers

LINQ != LINQ-to-SQL

LINQ is the concept, including some language support. There are many implementations - LINQ-to-SQL is one, as is ADO.NET Data Services, Entity Framework's LINQ-to-Entities, LINQ-to-Objects, LINQ-to-SQL, LINQ-to-Amazon, DbLinq, etc.

You still use LINQ with Entity Framework; indeed, LINQ-to-Entities is the preferred choice, giving compile time static checking. Entity SQL is simply another mechanism (in addition to LINQ-to-Entities) for querying the EDM (Entity Data Model).

There are 3 main reasons that ESQL is useful:

  • it was the only option in early previews when LINQ-to-Entities was still under construction
  • it can be used in some scenarios where there is no object model, for example reporting services
  • there is a small number of cases where ESQL is more expressive

For everything else, LINQ should be your tool for working with Entity Framework.

like image 67
Marc Gravell Avatar answered Oct 20 '22 01:10

Marc Gravell


LINQ is a generic term for the language features that permit queries to be written in C# or VB.NET over a data store of some sort. There is LINQ to SQL, LINQ to Entities, LINQ to Objects, etc.

LINQ to SQL closely models the physical database structure. It produces one type for every table in the database. If your database changes, then your LINQ to SQL code will need to change.

LINQ to Entities more closely models the conceptual database design. It allows you to map to the physical database, but for instance, allows you to create one Person entity that includes data from both the Person and Contacts tables. This allows your callers to think in terms of what the data mean instead of how the data are implemented.

Also, Microsoft has said that future development in LINQ to SQL will be limited when compared to the development in LINQ to Entities. Given the increased flexibility and the fact that LINQ to SQL won't get many more enhancements, I'd go with LINQ to Entities and Entity Framework.

like image 38
John Saunders Avatar answered Oct 20 '22 01:10

John Saunders


As others said, you probably mean Linq to SQL vs Entity Framework.

Both work for SQL Server, but only Entity Framework will work for other databases. Also, LINQ to SQL has, more or less, been depreciated. So go with Entity Framework.

like image 4
Chris Brandsma Avatar answered Oct 20 '22 00:10

Chris Brandsma


Linq is a programming construct that allows you query your objects

there is a Linq to Sql that I think you are talking about.

you can always use linq to query EF objects...

like image 1
Ali Shafai Avatar answered Oct 20 '22 01:10

Ali Shafai