How is Entity Framework different from LINQ to SQL? There is already a question in StackOverflow. Both technologies are somewhat similar. They provide an ORM framework. But, there are some important differences. LINQ to SQL has several limitations.

SQL Server only

LINQ to SQL works only with SQL Server, especially SQL 2005 and above. It works in a limited way with SQL 2000. Entity framework, on the other hand, works with most databases – Oracle, PostGres, DB2, MySQL and plenty more.

One-to-One mapping

LINQ to SQL is simpler than Entity Framework. It provides an exact one-to-one mapping between the database table and the class. With Entity framework, there is a many-to-many relation between the database table and the class. A single database table can map to multiple classes. Or a single class can map to multiple tables. For example, the Customer class and Address class can map to a single Customer table in the database.

No complex types

Entity framework allows complex types to be defined. For example, consider the Contact table with telephone number field. The telephone number is a complex type with properties such as international code, telephone number and extension.

Model file format

DBML file represents the model for LINQ to SQL. The model represents the mapping between the classes and the storage tables. An EDMX file stores the model for Entity Framework.

Database first approach

LINQ to SQL always has a Database first approach. Entity framework has three approaches: Database first, Model first and Code first.

  • Database first: Generate model and classes from database.
  • Model first: Generate database and classes from model.
  • Code first: Generate database and model from classes.
Entity Framework vs LINQ to SQL
Tagged on: