<p>Now that .NET v3.5 SP1 has been released (along with VS2008 SP1), we now have access to the .NET entity framework.</p>

<p>My question is this.  When trying to decide between using the Entity Framework and LINQ to SQL as an ORM, what's the difference?</p>

<p>The way I understand it, the Entity Framework (when used with LINQ to Entities) is a 'big brother' to LINQ to SQL?  If this is the case - what advantages does it have?  What can it do that LINQ to SQL can't do on its own?</p>

[{'answer_id': 8686, 'author': 'JamesSugrue', 'author_id': 1075, 'author_profile': 'https://Stackoverflow.com/users/1075', 'pm_score': 7, 'selected': False, 'text': '<p>There are a number of obvious differences outlined in that article @lars posted, but short answer is:</p>\n\n<ul>\n<li>L2S is tightly coupled - object property to specific field of database or more correctly object mapping to a specific database schema</li>\n<li>L2S will only work with SQL Server (as far as I know)</li>\n<li>EF allows mapping a single class to multiple tables </li>\n<li>EF will handle M-M relationships</li>\n<li>EF will have ability to target any ADO.NET data provider</li>\n</ul>\n\n<p>The original premise was L2S is for Rapid Development, and EF for more "enterprisey" n-tier applications, but that is selling L2S a little short.</p>\n'}, {'answer_id': 9004, 'author': 'Brad Tutterow', 'author_id': 308, 'author_profile': 'https://Stackoverflow.com/users/308', 'pm_score': 8, 'selected': False, 'text': '<p>I think the quick and dirty answer is that</p>\n\n<ul>\n<li>LINQ to SQL is the quick-and-easy way to do it.  This means you will get going quicker, and deliver quicker if you are working on something smaller.</li>\n<li>Entity Framework is the all-out, no-holds-barred way to do it.  This means you will take more time up-front, develop slower, and have more flexibility if you are working on something larger.</li>\n</ul>\n'}, {'answer_id': 80772, 'author': 'vintana', 'author_id': 13594, 'author_profile': 'https://Stackoverflow.com/users/13594', 'pm_score': 4, 'selected': False, 'text': '<p>If your database is straightforward and simple, LINQ to SQL will do. If you need logical/abstracted entities on top of your tables, then go for Entity Framework.</p>\n'}, {'answer_id': 110153, 'author': 'Kris', 'author_id': 14439, 'author_profile': 'https://Stackoverflow.com/users/14439', 'pm_score': 10, 'selected': True, 'text': '<p>LINQ to SQL only supports 1 to 1 mapping of database tables, views, sprocs and functions available in Microsoft SQL Server.  It\'s a great API to use for quick data access construction to relatively well designed SQL Server databases.  LINQ2SQL was first released with C# 3.0 and .Net Framework 3.5.</p>\n\n<p>LINQ to Entities (ADO.Net Entity Framework) is an ORM (Object Relational Mapper) API which allows for a broad definition of object domain models and their relationships to many different ADO.Net data providers.  As such, you can mix and match a number of different database vendors, application servers or protocols to design an aggregated mash-up of objects which are constructed from a variety of tables, sources, services, etc.  ADO.Net Framework was released with the .Net Framework 3.5 SP1.</p>\n\n<p>This is a good introductory article on MSDN:\n<a href="http://msdn.microsoft.com/en-us/library/cc161164.aspx" rel="noreferrer">Introducing LINQ to Relational Data</a></p>\n'}, {'answer_id': 259058, 'author': 'Zack Peterson', 'author_id': 83, 'author_profile': 'https://Stackoverflow.com/users/83', 'pm_score': 7, 'selected': False, 'text': '<p><a href="http://www.infoq.com/news/2008/11/DLINQ-Future" rel="noreferrer">Is LINQ to SQL Truly Dead?</a> by Jonathan Allen for InfoQ.com</p>\n<blockquote>\n<p>Matt Warren describes [LINQ to SQL] as something that &quot;was never even supposed to exist.&quot; Essentially, it was just supposed to be stand-in to help them develop LINQ until the real ORM was ready.</p>\n<p>...</p>\n<p>The scale of Entity Framework caused it to miss the .NET 3.5/Visual Studio 2008 deadline. It was completed in time for the unfortunately named &quot;.NET 3.5 Service Pack 1&quot;, which was more like a major release than a service pack.</p>\n<p>...</p>\n<p>Developers do not like [ADO.NET Entity Framework] because of the complexity.</p>\n<p>...</p>\n<p>as of .NET 4.0, LINQ to Entities will be the recommended data access solution for LINQ to relational scenarios.</p>\n</blockquote>\n'}, {'answer_id': 309968, 'author': 'terjetyl', 'author_id': 29519, 'author_profile': 'https://Stackoverflow.com/users/29519', 'pm_score': 5, 'selected': False, 'text': '<p>My impression is that your database is pretty enourmous or very badly designed if Linq2Sql does not fit your needs. I have around 10 websites both larger and smaller all using Linq2Sql. I have looked and Entity framework many times but I cannot find a good reason for using it over Linq2Sql. That said I try to use my databases as model so I already have a 1 to 1 mapping between model and database. </p>\n\n<p>At my current job we have a database with 200+ tables. An old database with lots of bad solutions so there I could see the benefit of Entity Framework over Linq2Sql but still I would prefer to redesign the database since the database is the engine of the application and if the database is badly designed and slow then my application will also be slow. Using Entity framework on such a database seems like a quickfix to disguise the bad model but it could never disguise the bad performance you get from such a database.</p>\n'}, {'answer_id': 348622, 'author': 'Jiyosub', 'author_id': 37591, 'author_profile': 'https://Stackoverflow.com/users/37591', 'pm_score': 6, 'selected': False, 'text': "<p>My experience with Entity Framework has been less than stellar.  First, you have to inherit from the EF base classes, so say good bye to POCOs.  Your design will have to be around the EF.  With LinqtoSQL I could use my existing business objects.  Additionally, there is no lazy loading, you have to implement that yourself.  There are some work arounds out there to use POCOs and lazy loading, but they exist IMHO because EF isn't ready yet.  I plan to come back to it after 4.0</p>\n"}, {'answer_id': 646239, 'author': 'MRFerocius', 'author_id': 72547, 'author_profile': 'https://Stackoverflow.com/users/72547', 'pm_score': 3, 'selected': False, 'text': '<p>I think if you need to develop something quick with no Strange things in the middle, and you need the facility to have entities representing your tables:</p>\n\n<p>Linq2Sql can be a good allied, using it with LinQ unleashes a great developing timing.</p>\n'}, {'answer_id': 764909, 'author': 'John Dunagan', 'author_id': 28939, 'author_profile': 'https://Stackoverflow.com/users/28939', 'pm_score': 3, 'selected': False, 'text': "<p>Neither yet supports the unique SQL 2008 datatypes. The difference from my perspective is that Entity still has a chance to construct a model around my geographic datatype in some future release, and Linq to SQL, being abandoned, never will.</p>\n\n<p>Wonder what's up with nHibernate, or OpenAccess...</p>\n"}, {'answer_id': 5031052, 'author': 'Banford', 'author_id': 162857, 'author_profile': 'https://Stackoverflow.com/users/162857', 'pm_score': 4, 'selected': False, 'text': "<p>I found that I couldn't use multiple databases within the same database model when using EF. But in linq2sql I could just by prefixing the schema names with database names. </p>\n\n<p>This was one of the reasons I originally began working with linq2sql. I do not know if EF has yet allowed this functionality, but I remember reading that it was intended for it not to allow this.</p>\n"}, {'answer_id': 9842355, 'author': 'Nawaz', 'author_id': 415784, 'author_profile': 'https://Stackoverflow.com/users/415784', 'pm_score': 6, 'selected': False, 'text': '<p>I found a very good answer <a href="http://www.dofactory.com/topic/1077/when-to-use-linq-to-sql-versus-entity-framework.aspx" rel="noreferrer">here</a> which explains when to use what in simple words:</p>\n<blockquote>\n<p>The basic rule of thumb for which framework to use is how to plan on\nediting your data in your presentation layer.</p>\n<ul>\n<li><p><strong>Linq-To-Sql</strong> - use this framework if you plan on editing a one-to-one\nrelationship of your data in your presentation layer.  Meaning you\ndon\'t plan on combining data from more than one table in any one view\nor page.</p>\n</li>\n<li><p><strong>Entity Framework</strong> - use this framework if you plan on\ncombining data from more than one table in your view or page. To make\nthis clearer, the above terms are specific to data that will be\nmanipulated in your view or page, not just displayed.  This is\nimportant to understand.</p>\n</li>\n</ul>\n<p>With the Entity Framework you are able to &quot;merge&quot; tabled data together\nto present to the presentation layer in an editable form, and then\nwhen that form is submitted, EF will know how to update ALL the data\nfrom the various tables.</p>\n<p>There are probably more accurate reasons to choose EF over L2S, but\nthis would probably be the easiest one to understand.  L2S does not\nhave the capability to merge data for view presentation.</p>\n</blockquote>\n'}, {'answer_id': 22446360, 'author': 'saille', 'author_id': 30246, 'author_profile': 'https://Stackoverflow.com/users/30246', 'pm_score': 5, 'selected': False, 'text': "<p>The answers here have covered many of the differences between Linq2Sql and EF, but there's a key point which has not been given much attention: Linq2Sql only supports SQL Server whereas EF has providers for the following RDBMS's:</p>\n\n<p>Provided by Microsoft:</p>\n\n<ul>\n<li>ADO.NET drivers for SQL Server, OBDC and OLE DB</li>\n</ul>\n\n<p>Via third party providers:</p>\n\n<ul>\n<li>MySQL</li>\n<li>Oracle</li>\n<li>DB2</li>\n<li>VistaDB</li>\n<li>SQLite</li>\n<li>PostgreSQL</li>\n<li>Informix</li>\n<li>U2</li>\n<li>Sybase</li>\n<li>Synergex</li>\n<li>Firebird</li>\n<li>Npgsql</li>\n</ul>\n\n<p>to name a few.</p>\n\n<p>This makes EF a powerful programming abstraction over your relational data store, meaning developers have a consistent programming model to work with regardless of the underlying data store. This could be very useful in situations where you are developing a product that you want to ensure will interoperate with a wide range of common RDBMS's.</p>\n\n<p>Another situation where that abstraction is useful is where you are part of a development team that works with a number of different customers, or different business units within an organisation, and you want to improve developer productivity by reducing the number of RDBMS's they have to become familiar with in order to support a range of different applications on top of different RDBMS's.</p>\n"}, {'answer_id': 29766760, 'author': 'Ryszard Dżegan', 'author_id': 2042090, 'author_profile': 'https://Stackoverflow.com/users/2042090', 'pm_score': 6, 'selected': False, 'text': '<h2>LINQ to SQL</h2>\n\n<ol>\n<li>Homogeneous datasource: SQL Server</li>\n<li>Recommended for small projects only where data structure is well designed</li>\n<li>Mapping can be changed without recompilling with SqlMetal.exe</li>\n<li>.dbml (Database Markup Language)</li>\n<li>One-to-one mapping between tables and classes</li>\n<li>Supports <a href="https://msdn.microsoft.com/en-us/library/vstudio/bb399352%28v=vs.100%29.aspx">TPH</a> inheritance</li>\n<li>Doesn\'t support complex types</li>\n<li>Storage-first approach</li>\n<li>Database-centric view of a database</li>\n<li>Created by C# team</li>\n<li>Supported but not further improvements intended</li>\n</ol>\n\n<h2>Entity Framework</h2>\n\n<ol>\n<li>Heterogeneus datasource: <a href="https://msdn.microsoft.com/en-us/data/jj730568#providers">Support many data providers</a></li>\n<li>Recommended for all new projects except:\n<ul>\n<li>small ones (LINQ to SQL)</li>\n<li>when data source is a flat file (ADO.NET)</li>\n</ul></li>\n<li>Mapping can be changed without recompilling when setting model and mapping files Metadata Artifact Process to Copy To Output Directory</li>\n<li>.edmx (Entity Data Model) which contains:\n<ul>\n<li>SSDL (Storage Schema Definition Language)</li>\n<li>CSDL (Conceptual Schema Definition Language)</li>\n<li>MSL (Mapping Specification Language)</li>\n</ul></li>\n<li>One-to-one, one-to-many, many-to-one mappings between tables and classes</li>\n<li>Supports inheritence:\n<ul>\n<li>TPH (Table Per Hierarchy)</li>\n<li>TPT (Table Per Type)</li>\n<li>TPC (Table Per Concrete Class)</li>\n</ul></li>\n<li>Supports complex types</li>\n<li>Code-first, Model-first, Storage-first approaches</li>\n<li>Application-centric view of a database</li>\n<li>Created by SQL Server team</li>\n<li>Future of Microsoft Data APIs</li>\n</ol>\n\n<hr>\n\n<p>See also:</p>\n\n<ul>\n<li><a href="http://jinaldesai.net/linq-to-sql-vs-entity-framework/">LINQ To SQL Vs Entity Framework</a></li>\n<li><a href="http://www.dotnet-tricks.com/Tutorial/entityframework/1M5W300314-Difference-between-LINQ-to-SQL-and-Entity-Framework.html">Difference between LINQ to SQL and Entity Framework</a></li>\n<li><a href="http://blogs.msdn.com/b/swiss_dpe_team/archive/2008/11/06/entity-framework-vs-linq-to-sql.aspx">Entity Framework vs LINQ TO SQL</a></li>\n</ul>\n'}, {'answer_id': 32319137, 'author': 'Omer', 'author_id': 1996435, 'author_profile': 'https://Stackoverflow.com/users/1996435', 'pm_score': 5, 'selected': False, 'text': '<div class="s-table-container">\n<table class="s-table">\n<thead>\n<tr>\n<th>LINQ to SQL</th>\n<th>Entity Framework</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It only works with SQL Server database</td>\n<td>It can work with various databases like Oracle, DB2, MySQL, SQL Server, etc.</td>\n</tr>\n<tr>\n<td>It generates .dbml to maintain the relation</td>\n<td>It generates a .edmx file initially. The relation is maintained using 3 different files; .csdl, .msl and .ssdl</td>\n</tr>\n<tr>\n<td>It has not to support for complex types</td>\n<td>It has support for complex types</td>\n</tr>\n<tr>\n<td>It cannot generate database from model</td>\n<td>It can generate database from model</td>\n</tr>\n<tr>\n<td>It allows only one-to-one mapping between the entity classes and the relational tables/views</td>\n<td>It allows one-to-one, one-to-many, many-to-many mappings between the entity classes and relational tables/views</td>\n</tr>\n<tr>\n<td>It allows you to query data using DataContext</td>\n<td>It allows you to query data using EntitySQL, ObjectContext, DbContext</td>\n</tr>\n<tr>\n<td>It can be used for rapid application development only with SQL Server</td>\n<td>It can be used for rapid application development with RDBMS like SQL Server, Oracle, PostgreSQL, etc.</td>\n</tr>\n</tbody>\n</table>\n</div>'}, {'answer_id': 42359474, 'author': 'Umang Patwa', 'author_id': 6541065, 'author_profile': 'https://Stackoverflow.com/users/6541065', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>Linq-to-SQL</p>\n</blockquote>\n\n<p><em>It is provider it supports SQL Server only. It's a mapping technology to map SQL Server database tables to .NET objects. Is Microsoft's first attempt at an ORM - Object-Relational Mapper.</em></p>\n\n<blockquote>\n  <p>Linq-to-Entities</p>\n</blockquote>\n\n<p><em>Is the same idea, but using Entity Framework in the background, as the ORM - again from Microsoft, It supporting multiple database main advantage of entity framework is developer can work on any database no need to learn syntax to perform any operation on different different databases</em></p>\n\n<blockquote>\n  <p>According to my personal experience Ef is better (if you have no idea about SQL)\n  performance in LINQ is little bit faster as compare to EF reason LINQ language written in lambda.</p>\n</blockquote>\n"}, {'answer_id': 43834680, 'author': 'Ramon de Klein', 'author_id': 956435, 'author_profile': 'https://Stackoverflow.com/users/956435', 'pm_score': 3, 'selected': False, 'text': '<p>I am working for  customer that has a big project that is using Linq-to-SQL. When the project started it was the obvious choice, because Entity Framework was lacking some major features at that time and performance of Linq-to-SQL was much better.</p>\n\n<p>Now EF has evolved and Linq-to-SQL is lacking async support, which is great for highly scalable services. We have 100+ requests per second sometimes and despite we have optimized our databases, most queries still take several milliseconds to complete. Because of the synchronous database calls, the thread is blocked and not available for other requests.</p>\n\n<p>We are thinking to switch to Entity Framework, solely for this feature. It\'s a shame that Microsoft didn\'t implement async support into Linq-to-SQL (or open-sourced it, so the community could do it).</p>\n\n<p><strong>Addendum December 2018:</strong> Microsoft is moving towards .NET Core and Linq-2-SQL isn\'t support on .NET Core, so you need to move to EF to make sure you can migrate to EF.Core in the future.</p>\n\n<p>There are also some other options to consider, such as <a href="https://www.llblgen.com/" rel="nofollow noreferrer">LLBLGen</a>. It\'s a mature ORM solution that exists already a long time and has been proven more future-proof then the MS data solutions (ODBC, ADO, ADO.NET, Linq-2-SQL, EF, EF.core).</p>\n'}, {'answer_id': 63476371, 'author': 'Robert Green MBA', 'author_id': 663853, 'author_profile': 'https://Stackoverflow.com/users/663853', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Here\'s some metrics guys... (QUANTIFYING THINGS!!!!)</strong></p>\n<p>I took this query where I was using Entity Framework</p>\n<pre><code>var result = (from metattachType in _dbContext.METATTACH_TYPE\n                join lineItemMetattachType in _dbContext.LINE_ITEM_METATTACH_TYPE on metattachType.ID equals lineItemMetattachType.METATTACH_TYPE_ID\n                where (lineItemMetattachType.LINE_ITEM_ID == lineItemId &amp;&amp; lineItemMetattachType.IS_DELETED == false\n                &amp;&amp; metattachType.IS_DELETED == false)\n                select new MetattachTypeDto()\n                {\n                    Id = metattachType.ID,\n                    Name = metattachType.NAME\n                }).ToList();\n</code></pre>\n<p>and changed it into this where I\'m using the repository pattern\nLinq</p>\n<pre><code>            return await _attachmentTypeRepository.GetAll().Where(x =&gt; !x.IsDeleted)\n                .Join(_lineItemAttachmentTypeRepository.GetAll().Where(x =&gt; x.LineItemId == lineItemId &amp;&amp; !x.IsDeleted),\n                attachmentType =&gt; attachmentType.Id,\n                lineItemAttachmentType =&gt; lineItemAttachmentType.MetattachTypeId,\n                (attachmentType, lineItemAttachmentType) =&gt; new AttachmentTypeDto\n                {\n                    Id = attachmentType.Id,\n                    Name = attachmentType.Name\n                }).ToListAsync().ConfigureAwait(false);\n</code></pre>\n<p>Linq-to-sql</p>\n<pre><code>            return (from attachmentType in _attachmentTypeRepository.GetAll()\n                    join lineItemAttachmentType in _lineItemAttachmentTypeRepository.GetAll() on attachmentType.Id equals lineItemAttachmentType.MetattachTypeId\n                    where (lineItemAttachmentType.LineItemId == lineItemId &amp;&amp; !lineItemAttachmentType.IsDeleted &amp;&amp; !attachmentType.IsDeleted)\n                    select new AttachmentTypeDto()\n                    {\n                        Id = attachmentType.Id,\n                        Name = attachmentType.Name\n                    }).ToList();\n</code></pre>\n<p>Also, please know that Linq-to-Sql is 14x faster than Linq...</p>\n<p><a href="https://i.stack.imgur.com/TkWAZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TkWAZ.jpg" alt="enter image description here" /></a></p>\n'}]
['https://Stackoverflow.com/questions/8676', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/475/']