what is the difference between linq to sql classes and entity framework seem that they same work like both which is better in .net3.5 and why? *which is better in .net4 and why?*
Asked
Active
Viewed 2,451 times
2 Answers
9
Briefly:
Linq-to-SQL is:
- a "proof-of-concept" done by the Visual C# team to show off the capabilities of Linq
- a straight 1:1 mapper - one table becomes one entity in your code
- for SQL Server only
- not very well suited to support stored procedures (you cannot e.g. create "complex types" to mirror values returned from your stored procedure)
- designer-driven, database-first only approach (and model cannot be easily updated if your database changes)
- basically a dead-end technology - there might be bug fixes here and there, but certainly no new features; it works - but don't expect any further development on this
--> so Linq-to-SQL works, and quite well in .NET 3.5 - but don't expect anything new here....
Entity Framework (at least in .NET v4 and up) is:
- a "proper" OR-mapper technology (and more) done by the ADO.NET/database teams at Microsoft
- a flexible mapper with a physical layer (database schema), a conceptual layer (your .NET objects), and a mapping layer between those two (three-layer approach)
- supports several databases (SQL Server, Oracle etc.) out of the box - fairly easy to write an Entity Framework compatible provider for other databases
- supports stored procedures very well (you can even pick a stored proc for one entity and one operation, e.g. for the DELETE)
- offer database-first, model-first and code-first development approaches
- if using model - that model can be updated from the database if your tables change over time
- the product that Microsoft is investing lots of their resources into - still being very actively developed (additional features, new approachs like code-first development etc.)
--> Entity Framework is my clear choice for .NET 4 and newer

marc_s
- 732,580
- 175
- 1,330
- 1,459
1
There are a lot of comparison analysis made on this topic:
Performance comparison: Entity Framework and LINQ to SQL Performance
Features comparison: LINQ to SQL vs Entity Framework
And also related topics can be found in StackOverflow