91,850 questions
885
votes
29
answers
964k
views
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details [duplicate]
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 ...
842
votes
12
answers
715k
views
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 ...
817
votes
31
answers
606k
views
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 ...
734
votes
47
answers
569k
views
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 ...
658
votes
10
answers
360k
views
Code-first vs Model/Database-first [closed]
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 ...
601
votes
36
answers
474k
views
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'
After downloading EF6 via NuGet and trying 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'. ...
539
votes
10
answers
428k
views
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 ...
466
votes
10
answers
255k
views
Why use ICollection and not IEnumerable or List<T> on many-many/one-many relationships? [closed]
I see this a lot in tutorials, with navigation properties as ICollection<T>.
Is this a mandatory requirement for Entity Framework? Can I use IEnumerable?
What's the main purpose of using ...
449
votes
9
answers
122k
views
One DbContext per web request... why?
I have been reading a lot of articles explaining how to set up Entity Framework's DbContext so that only one is created and used per HTTP web request using various DI frameworks.
Why is this a good ...
445
votes
5
answers
188k
views
Entity Framework VS LINQ to SQL VS ADO.NET with stored procedures? [closed]
How would you rate each of them in terms of:
Performance
Speed of development
Neat, intuitive, maintainable code
Flexibility
Overall
I like my SQL and so have always been a die-hard fan of ADO.NET and ...
430
votes
14
answers
302k
views
The entity cannot be constructed in a LINQ to Entities query
There is an entity type called Product that is generated by entity framework.
I have written this query
public IQueryable<Product> GetProducts(int categoryID)
{
return from p in db.Products
...
423
votes
39
answers
550k
views
Error message 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.'
I have developed an application using Entity Framework, SQL Server 2000, Visual Studio 2008 and Enterprise Library.
It works absolutely fine locally, but when I deploy the project to our test ...
407
votes
10
answers
444k
views
Entity Framework Timeouts
I am getting timeouts using the Entity Framework (EF) when using a function import that takes over 30 seconds to complete. I tried the following and have not been able to resolve this issue:
I added ...
384
votes
18
answers
330k
views
Reset Entity-Framework Migrations
I've mucked up my migrations, I used IgnoreChanges on the initial migration, but now I want to delete all my migrations and start with an initial migration with all of the logic.
When I delete the ...
370
votes
4
answers
314k
views
Using Transactions or SaveChanges(false) and AcceptAllChanges()?
I have been investigating transactions and it appears that they take care of themselves in EF as long as I pass false to SaveChanges() and then call AcceptAllChanges() if there are no errors:
...
357
votes
45
answers
424k
views
Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0)." [closed]
I am using Entity Framework to populate a grid control. Sometimes when I make updates I get the following error:
Store update, insert, or delete statement affected an unexpected number of rows (0). ...
341
votes
12
answers
357k
views
Entity Framework Core add unique constraint code-first
I can't find way to add a unique constraint to my field with using attribute:
public class User
{
[Required]
public int Id { get; set; }
[Required]
// [Index("IX_FirstAndSecond", 2, ...
335
votes
20
answers
943k
views
How to update record using Entity Framework 6?
I am trying to update a record using EF6. First finding the record, if it exists, update.
Here is my code:
var book = new Model.Book
{
BookNumber = _book.BookNumber,
BookName = _book.BookName,...
328
votes
7
answers
156k
views
Create code first, many to many, with additional fields in association table
I have this scenario:
public class Member
{
public int MemberID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection&...
312
votes
22
answers
622k
views
How to call Stored Procedure in Entity Framework 6 (Code-First)?
I am very new to Entity Framework 6 and I want to implement stored procedures in my project. I have a stored procedure as follows:
ALTER PROCEDURE [dbo].[insert_department]
@Name [varchar](100)
...
301
votes
9
answers
351k
views
Non-static method requires a target
I have a controller action that works fine on Firefox both locally and in production, and IE locally, but not IE in production. Here is my controller action:
public ActionResult MNPurchase()
{
...
285
votes
11
answers
193k
views
Entity Framework: One Database, Multiple DbContexts. Is this a bad idea? [closed]
My impression to date has been that a DbContext is meant to represent your database, and thus, if your application uses one database, you'd want only one DbContext.
However, some colleagues want to ...
277
votes
3
answers
124k
views
What does principal end of an association means in 1:1 relationship in Entity framework
public class Foo
{
public string FooId{get;set;}
public Boo Boo{get;set;}
}
public class Boo
{
public string BooId{get;set;}
public Foo Foo{get;set;}
}
I was trying to do this in ...
271
votes
23
answers
416k
views
Entity Framework Core: A second operation started on this context before a previous operation completed [duplicate]
I'm working on a ASP.Net Core 2.0 project using Entity Framework Core
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference ...
269
votes
3
answers
165k
views
Linq-to-Entities Join vs GroupJoin
Can someone please explain what a GroupJoin() is?
How is it different from a regular Join()?
Is it commonly used?
Is it only for method syntax? What about query syntax? (A c# code example would be ...