QBoard » Artificial Intelligence & ML » AI and ML - R » what is the difference between linq to sql class and entity framework

what is the difference between linq to sql class and entity framework

  • what is the difference between linq to sql class and entity framework and what kind of situation linq to sql should use and when entity framework will be the best option.
      September 24, 2021 12:40 PM IST
    0
  • They are somewhat similar, and can be used in a very similar way, code-wise, but they have some important differences. Note that "LINQ" is not the same thing as "LINQ to SQL"; the EF also uses LINQ. Some notable differences are:

    • LINQ to SQL is largely SQL Server only, not so much by design as by implementation. The EF is designed to support, and does support, multiple DBs, if you have a compatible ADO.NET provider.
    • Out of the box, LINQ to SQL has a very poor story for DB metadata changes. You have to regenerate parts of your model from scratch, and you lose customizations.
    • The EF supports model features like many-to-many relationships and inheritance. LINQ to SQL does not directly support these.
    • In .NET 3.5, LINQ to SQL had much better support for SQL-Server-specific functionality than the EF. This is mostly not true in .NET 4; they're fairly similar in that respect.
    • The EF lets you choose Model First, DB First, or Code First modeling. LINQ to SQL, out of the box, really only supports DB First.
      November 30, 2021 11:51 AM IST
    0
  • Latest EF is lot more robust, and you're not forced into a designer driven pseudo-ORM experience (or a morass of config if you tried to do it without the designer). Your model can be POCO objects now instead of some designer driven partial class mangled bs that's intrinsicly coupled with designer driven code, you can get away from the designer entirely without feeling like you're swimming upstream, and in general it just feels like they have listened to the community or actually tried to emulate existing, battle-tested solutions instead of making a version for the "Morts" or whatever L2Sql was supposed to be.
      December 1, 2021 10:56 AM IST
    0
  • Check out this link for a quick comparison. For me linq to sql is a quicker way to get a small application up and running and the entity framework is more for large more complex applications that you can take time to build a big foundation for.

     
      September 24, 2021 1:49 PM IST
    0
  • 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

      January 1, 2022 2:02 PM IST
    0
  • S.No LINQ To SQL Entity Framework
    1. LINQ to SQL only works with SQL Server. It works with various RDBMS like Oracle, MySQL, SQL Server, DB2
    2 LINQ to SQL cannot generate the database based on model classes. Entity Framework generates the database based on model classes
    3 LINQ to SQL uses the Data Context class to interact with a database. Entity Framework generates the DBContext class to interact with the database.
    4 LINQ to SQL is tightly coupled. Entity Framework is Loosely Coupled
    5 It supports only 1-1 relation while mapping the relational tables with classes. It supports the 1-1, 1-*, *-1, *-* relation while mapping relation tables with classes
    6 It does not support the complex type. It supports the complex type
    7 It will generate the DBML file (Database Mark up Language) and the file with 3 sections to represents the schema: csdl, msl,ssdl It generates the .EDMX file (Entity Data Model Extension)
    8 Very slow for the first query Very slow for the first query. But overall performance is better than LINQ TO SQL
    9 Rapid Development Development time is slower than LINQ to SQL but it provides more capabilities
    10 LINQ TO SQL works based on ORM Pattern Entity Framework also works based on ORM Pattern
      September 25, 2021 2:31 PM IST
    0
  • LINQ to SQL
    Entity Framework
    It only works with SQL Server Database.
    It can works with various databases like Oracle, DB2, MYSQL, SQL Server etc.
    It generates a .dbml to maintain the relation
    It generates an .edmx files initially. The relation is maintained using 3 different files .csdl, .msl and .ssdl
    It has not support for complex type.
    It has support for complex type.
    It cannot generate database from model.
    It can generate database from model.
    It allows only one to one mapping between the entity classes and the relational tables /views.
    It allows one-to-one, one-to-many & many-to-many mappings between the Entity classes and the relational tables /views
    It allows you to query data using DataContext.
    It allows you to query data using EntitySQL, ObjectContext, DbContext.
    It provides a tightly coupled approach.
    It provides a loosely coupled approach. Since its code first approach allow you to use Dependency Injection pattern which make it loosely coupled .
    It can be used for rapid application development only with SQL Server.
    It can be used for rapid application development with RDBMS like SQL Server, Oracle, DB2 and MySQL etc.
      September 30, 2021 12:47 PM IST
    0