Questions tagged [entity-framework]

Entity Framework is a LINQ-based object-database mapper for .NET. It supports change tracking, updates, and schema migrations for many databases. Please add a version-specific tag as well.

Entity Framework is .NET's Object-Relational Mapping (ORM) tool that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write. Either natively, or through third-party libraries, it supports most major RDBM products including SQL Server, MySQL, Oracle, PostgreSQL and SQLite. It also supports Microsoft's "LINQ" syntax and lambda-expressions.

Entity Framework was first developed for .Net framework (production-ready versions 4.x - 6.x). In 2016, Entity Framework for .Net core (EF-core) was introduced, having a completely new codebase which shares many concepts with the classic framework but differs considerably in mapping syntax, query translation and specific features. After version 1 and 2, EF-core 3 came with many breaking changes, marking the beginning of a more stable evolution path. EF core 5 (versions keep track with .Net core versions) has far less breaking changes.

As of version 6.3.0, EF 6 is cross-platform. It targets .Net standard 2.1. NuGet packages are available for .Net core 3 and .NET Framework 4.x.

Because of all these different versions it's very important to use the right tags when asking questions.

Entity Framework is well-documented.

91477 questions
29 answers

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details

I am having this error when seeding my database with code first approach. Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. To be honest I don't know how to check the content of the validation…
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506
17 answers

Entity Framework vs LINQ to SQL

Now that .NET v3.5 SP1 has been released (along with VS2008 SP1), we now have access to the .NET entity framework. My question is this. When trying to decide between using the Entity Framework and LINQ to SQL as an ORM, what's the difference? The…
Chris Roberts
  • 18,622
  • 12
  • 60
  • 67
32 answers

Fastest Way of Inserting in Entity Framework

I'm looking for the fastest way of inserting in Entity Framework. I'm asking this because of the scenario where you have an active TransactionScope and the insertion is huge (4000+). It can potentially last more than 10 minutes (default timeout of…
Bongo Sharp
  • 9,450
  • 8
  • 25
  • 35
12 answers

How can I retrieve Id of inserted entity using Entity framework?

I have a problem with Entity Framework in ASP.NET. I want to get the Id value whenever I add an object to database. How can I do this? According to Entity Framework the solution is: using (var context = new EntityContext()) { var customer = new…
  • 8,003
  • 3
  • 15
  • 3
24 answers

How do I view the SQL generated by the Entity Framework?

How do I view the SQL generated by entity framework ? (In my particular case I'm using the mysql provider - if it matters)
  • 223,662
  • 58
  • 417
  • 506
21 answers

There is already an open DataReader associated with this Command which must be closed first

I have this query and I get the error in this function: var accounts = from account in context.Accounts from guranteer in account.Gurantors select new AccountsReport { CreditRegistryId…
  • 27,428
  • 62
  • 183
  • 316
47 answers

MetadataException: Unable to load the specified metadata resource

All of a sudden I keep getting a MetadataException on instantiating my generated ObjectContext class. The connection string in App.Config looks correct - hasn't changed since last it worked - and I've tried regenerating a new model (edmx-file) from…
J. Steen
  • 15,470
  • 15
  • 56
  • 63
23 answers

SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session

I am currently getting this error: System.Data.SqlClient.SqlException: New transaction is not allowed because there are other threads running in the session. while running this code: public class ProductManager : IProductManager { #region…
Keith Barrows
  • 24,802
  • 26
  • 88
  • 134
10 answers

Code-first vs Model/Database-first

What are the pros & cons of using Entity Framework 4.1 Code-first over Model/Database-first with EDMX diagram? I'm trying to fully understand all the approaches to building data access layer using EF 4.1. I'm using Repository pattern and IoC. I know…
35 answers

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

After downloading the EF6 by nuget and try to run my project, it returns the following error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the…
Fernando Vellozo
  • 6,195
  • 2
  • 14
  • 12
22 answers

Unable to update the EntitySet - because it has a DefiningQuery and no element exist

I am using Entity Framework 1 with .net 3.5. I am doing something simple like this: var roomDetails = context.Rooms.ToList(); foreach (var room in roomDetails) { room.LastUpdated = DateTime.Now; } I am getting this error when I try to…
  • 9,151
  • 14
  • 57
  • 84
16 answers

EF Migrations: Rollback last applied migration?

This looks like a really common task, but I can't find an easy way to do it. I want to undo the last applied migration. I would have expected a simple command, like PM> Update-Database -TargetMigration:"-1" Instead, all I can come up with is: PM>…
10 answers

Entity Framework - Include Multiple Levels of Properties

The Include() method works quite well for Lists on objects. But what if I need to go two levels deep? For example, the method below will return ApplicationServers with the included properties shown here. However, ApplicationsWithOverrideGroup is…
Bob Horn
  • 33,387
  • 34
  • 113
  • 219
27 answers

Conversion of a datetime2 data type to a datetime data type results out-of-range value

I've got a datatable with 5 columns, where a row is being filled with data then saved to the database via a transaction. While saving, an error is returned: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range…
  • 5,274
  • 4
  • 29
  • 34
34 answers

Entity Framework Provider type could not be loaded?

I am trying to run my tests on TeamCity which is currently installed on my machine. System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer,…
ashutosh raina
  • 9,228
  • 12
  • 44
  • 80
2 3
99 100