Questions tagged [entity-framework-5]

The ADO.NET Entity Framework version 5, containing support for .net 4.5

entity-framework-5
Filter by
Sorted by
Tagged with
896 votes
9 answers
456k views

Entity Framework 5 Updating a Record

I have been exploring different methods of editing/updating a record within Entity Framework 5 in an ASP.NET MVC3 environment, but so far none of them tick all of the boxes I need. I'll explain why. ...
Stokedout's user avatar
  • 11k
295 votes
9 answers
331k 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() { ...
user547794's user avatar
  • 14.4k
219 votes
5 answers
106k views

What's the difference(s) between .ToList(), .AsEnumerable(), AsQueryable()?

I know some differences of LINQ to Entities and LINQ to Objects which the first implements IQueryable and the second implements IEnumerable and my question scope is within EF 5. My question is what'...
Amin Saqi's user avatar
  • 18.7k
197 votes
7 answers
254k views

EF LINQ include multiple and nested entities

Ok, I have tri-leveled entities with the following hierarchy: Course -> Module -> Chapter Here was the original EF LINQ statement: Course course = db.Courses .Include(i => i....
AnimaSola's user avatar
  • 7,486
181 votes
2 answers
484k views

Entity Framework Join 3 Tables

I'm trying to join three tables but I can't understand the method... I completed join 2 tables var entryPoint = dbContext.tbl_EntryPoint .Join(dbContext.tbl_Entry, ...
Erçin Dedeoğlu's user avatar
178 votes
4 answers
163k views

How to include a child object's child object in Entity Framework 5

I am using Entity Framework 5 code first and ASP.NET MVC 3. I am struggling to get a child object's child object to populate. Below are my classes.. Application class; public class Application { ...
Brendan Vogt's user avatar
  • 25.9k
177 votes
10 answers
179k views

Entity Framework Migrations renaming tables and columns

I renamed a a couple entities and their navigation properties and generated a new Migration in EF 5. As is usual with renames in EF migrations, by default it was going to drop objects and recreate ...
CatDadCode's user avatar
  • 58.7k
156 votes
7 answers
48k views

Debug code-first Entity Framework migration codes

I'm using Entity Framework code first in my website and I'm just wondering if there is any way to debug the migration codes. You know, like setting breakpoints and stuff like this. I'm using Package ...
Daniel's user avatar
  • 3,328
145 votes
28 answers
152k views

The term 'Update-Database' is not recognized as the name of a cmdlet

I am using EF5 beta1 and while I was able to run the "Update-Database" before. Now that I shut down Visual Studio, I cannot get it to run. I get the following error: The term 'Update-Database' is ...
user1265146's user avatar
  • 2,035
142 votes
12 answers
62k views

EF5: Cannot attach the file ‘{0}' as database '{1}'

I'm encountering the exact issue as described here (read section "Cannot Attach to Deleted MDF File"), but the solution to the problem is not told there... In short the issue is that after deleting ...
Shimmy Weitzhandler's user avatar
133 votes
6 answers
140k views

How do I enable EF migrations for multiple contexts to separate databases?

How do I enable Entity Framework 5 (version 5.0.0) migrations for multiple DB contexts in the same project, where each context corresponds to its own database? When I run Enable-Migrations in the PM ...
aknuds1's user avatar
  • 66.8k
122 votes
12 answers
257k views

Could not load file or assembly Microsoft.SqlServer.management.sdk.sfc version 11.0.0.0

I have installed MS SQL Server 2008 R2 and when I try to update model from database under EDMX file I am facing that error. Could not load file or assembly Microsoft.SqlServer.management.sdk.sfc ...
NoWar's user avatar
  • 37k
119 votes
5 answers
30k views

How to "warm-up" Entity Framework? When does it get "cold"?

No, the answer to my second question is not the winter. Preface: I've been doing a lot of research on Entity Framework recently and something that keeps bothering me is its performance when the ...
user avatar
115 votes
7 answers
38k views

Debugging Package Manager Console Update-Database Seed Method

I wanted to debug the Seed() method in my Entity Framework database configuration class when I run Update-Database from the Package Manager Console but didn't know how to do it. I wanted to share the ...
Sachin Kainth's user avatar
107 votes
7 answers
126k views

Calculated column in EF Code First

I need to have one column in my database calculated by database as (sum of rows) - (sum of rowsb). I'm using code-first model to create my database. Here is what I mean: public class Income { [...
CodeDemen's user avatar
  • 1,901
100 votes
6 answers
174k views

Mocking EF DbContext with Moq

I'm trying to create a unit test for my service with a mocked DbContext. I created an interface IDbContext with the following functions: public interface IDbContext : IDisposable { IDbSet<T>...
Gaui's user avatar
  • 8,793
90 votes
8 answers
94k views

How do I undo the last Add-Migration command?

I have created a migration using the Add-Migration command, but I'd like to change the name of that migration. How can I undo the migration command, so that I can regenerate it using the new desired ...
Miguel Angelo's user avatar
84 votes
8 answers
75k views

Entity Framework (.NET Full Framework) Ordering Includes [duplicate]

I am trying to get something like the following to work: _dbmsParentSections = FactoryTools.Factory.PdfSections .Include(x => x.Children.OrderBy(y => y.Order).ToList()) ...
Serj Sagan's user avatar
  • 29.5k
82 votes
3 answers
33k views

Check if there are any pending changes to be saved

Is there a way to find out whether there are unsaved changes in my entity context, in the Entity Framework?
Palantir's user avatar
  • 23.9k
81 votes
4 answers
53k views

Entity Framework 5 deep copy/clone of an entity

I am using Entity Framework 5 (DBContext) and I am trying to find the best way to deep copy an entity (i.e. copy the entity and all related objects) and then save the new entities in the database. How ...
kypk's user avatar
  • 813
80 votes
8 answers
48k views

How to rename a database column in Entity Framework 5 Code First migrations without losing data?

I got the default ASP.NET MVC 4 template successfully running with EF 5.0 Code First Migrations. However, when I update a model property name, the corresponding table column data is dropped by EF 5.0. ...
Dante's user avatar
  • 11k
78 votes
1 answer
64k views

Entity Framework Multiple Column as Primary Key by Fluent Api

These are my simplified domain classes. public class ProductCategory { public int ProductId { get; set; } public int CategoryId { get; set; } public virtual Product Product { get; set; } ...
Barış Velioğlu's user avatar
71 votes
10 answers
77k views

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

Using EF5 with a generic Repository Pattern and ninject for dependency injenction and running into an issue when trying to update an entity to the database utilizing stored procs with my edmx. my ...
Juan's user avatar
  • 1,144
62 votes
5 answers
20k views

How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5. There are some unit tests that depend on a database. Setting up the app.config file in the test project to use a central SQL ...
Klas Mellbourn's user avatar
61 votes
1 answer
101k views

Creating Composite Key Entity Framework

Shortly, I want to create composite keys on my table remaining with the primary key in order to improve sql server search performance. The performance issue occurs on 200k data table whenever I search ...
kkocabiyik's user avatar
  • 4,296
60 votes
6 answers
60k views

EF migration for changing data type of columns

I have a Model in my project as below: public class Model { public int Id { get; set; } public long FromNo { get; set; } public long ToNo { get; set; } public string Content { get; ...
Pooya Yazdani's user avatar
59 votes
3 answers
122k views

Entity Framework (EF) Code First Cascade Delete for One-to-Zero-or-One relationship

Following the "Code First Modeling" section of the Pluralsight "Getting Started with Entity Framework 5" course by Julie Lerman, I created two POCO classes with a one-to-zero-or-one relationship: a ...
arsenalogy's user avatar
59 votes
4 answers
14k views

Improve navigation property names when reverse engineering a database

I'm using Entity Framework 5 with Visual Studio with Entity Framework Power Tools Beta 2 to reverse engineer moderately sized databases (~100 tables). Unfortunately, the navigation properties do not ...
marapet's user avatar
  • 55.6k
55 votes
4 answers
75k views

DbContext AutoDetectChangesEnabled set to false detecting changes

I'm a bit stumped. From what I've read setting the DbContext.AutoDetectChangesEnabled to false should disable change tracking requiring one to call DbContext.DetectChanges in order to identify changes ...
Jesse's user avatar
  • 1,703
55 votes
5 answers
119k views

Get return value from stored procedure

I'm using Entity Framework 5 with the Code First approach. I need to read the return value from a stored procedure; I am already reading output parameters and sending input parameters, but I don't ...
Daniele Armanasco's user avatar
54 votes
11 answers
115k views

After updating Entity Framework model, Visual Studio does not see changes

If I do any changes to my EF 5.0 model, VS does not seem to see the changes. I have tried adding a new table, which shows up fine in the model, but then if I try to use it somewhere the table does not ...
Kyle's user avatar
  • 33.2k
54 votes
28 answers
165k views

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

I'm working with EF5 in a MVC 4 aspnet website. Locally, everything works just fine, but when I publish it to the IIS and try to enter, I get the error "The type initializer for 'System.Data.Entity....
polonskyg's user avatar
  • 4,279
54 votes
3 answers
59k views

Is it possible to set a unique constraint using Entity Framework Code First?

I want to enforce Unique constraint in a table & I am using Entity Framework Code-First. Is it possible to add a unique constraint using EF 6 as i believe in earlier versions it was not possible.
subi_speedrunner's user avatar
54 votes
5 answers
14k views

Consolidating EF migrations into new InitialCreate

I have been using EF migrations for some time now and have more than 100 migration files in my project. I would like to consolidate these into a single migration before moving forward - ie I want to ...
Paul Hiles's user avatar
  • 9,658
53 votes
1 answer
44k views

Non-static method requires a target. Entity Framework 5 Code First

I am getting the error "Non-static method requires a target." when I run the following query: var allPartners = DbContext.User .Include(u => u.Businesses) ...
ilivewithian's user avatar
  • 19.6k
48 votes
4 answers
49k views

EF5 Code First - Changing A Column Type With Migrations

I am new to EF5 Code First and I'm tinkering with a proof-of-concept before embarking on a project at work. I have initially created a model that looked something like public class Person { public ...
Nick's user avatar
  • 4,175
47 votes
3 answers
57k views

How to update only one table for model from database with Entity Framework?

I have a model generated from db with Entity Framework. When I have any change in database, I update model from database to get the change in model. But this update is applied to all entities (tables) ...
KentZhou's user avatar
  • 25.2k
44 votes
4 answers
37k views

EF5 Starting a Project:Error Running transformation: Please overwrite the replacement token '$edmxInputFile$'

I'm creating a Console Project in VS2012 with .Net4.5. After it I "Add", "New Item" to the project, and choose "EF 5.x DbContext Generator". Then, after a couple of seconds the following error message ...
Gil's user avatar
  • 1,123
43 votes
3 answers
40k views

Automatic Migrations for ASP.NET SimpleMembershipProvider

So I tried to use automatic migrations with my new MVC 4 Project but somehow it isn't working. I followed this blog post step by step. I've added the changes to the UserProfile account model (the ...
Erre Efe's user avatar
  • 15.5k
43 votes
2 answers
27k views

Cannot enable migrations for Entity Framework in class library

I just got on board with EF 5 and am using their code-first migrations tool but I seem to get an error when I try to enable migrations. I type Enable-Migrations into the package manager console and ...
CatDadCode's user avatar
  • 58.7k
43 votes
4 answers
58k views

Upgrade from Entity Framework 5 to 6

After upgrading our project from using Entity Framework 5 to Entity Framework 6 (though NuGets update function) i get the following error on my generated Entities class: Error 1 The type or ...
RossBille's user avatar
  • 1,459
43 votes
2 answers
9k views

EF5 Migration Update-Database -Script Error

I've been using Visual Studio 2012 RC with trial license with no problems. I purchased Visual Studio 2012 Professional yesterday, installed the latest version, and installed Update 1. I have a ...
Sean Newcome's user avatar
  • 1,497
42 votes
1 answer
78k views

Entity Framework - attribute IN Clause usage

I need to filter some Entities by various fields using "normal" WHERE and IN clauses in a query over my database, but I do not know how to do that with EF. This is the approach: Database table ...
unairoldan's user avatar
  • 2,815
42 votes
7 answers
45k views

Batch update/delete EF5

What is the best way to deal with batch updates using (Entity Framework) EF5? I have 2 particular cases I'm interested in: Updating a field (e.g. UpdateDate) for a list (List) of between 100 and 100....
Frank's user avatar
  • 4,009
40 votes
1 answer
21k views

EntityFramework 5 use dll version 4.4.0.instead 5.0

I have project based on .NET 4.0 but I need to use EntityFramework 5 in my solution. So I install it from the NuGet. After that I change target framework to .NET 4.5 (I'm using VS 2012) and rebuild ...
Rroman's user avatar
  • 666
40 votes
1 answer
46k views

How do I specify the maximum column length of a field using entity framework code first

Is there an attribute I can use when creating a table ? I tried [StringLength] but it seems to be ignored. public class EntityRegister { public int Id { get; set; } [StringLength(450)] ...
Kirsten's user avatar
  • 16.8k
39 votes
4 answers
23k views

Entity Framework: I set the foreign key, SaveChanges then access the navigation property, but it doesn't load the related entity. Why not?

I am using this Entity class with Entity Framework 5 Code First: public class Survey { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } public string ...
Colin's user avatar
  • 22.4k
38 votes
3 answers
83k views

How to install EntityFramework 5.0 (and other older versions) from NuGet?

I installed EF 5.0 into the .DAL, now I want to install EF 5.0 into .BLL from Nuget But the default online Nuget package always comes up with 6.0, which gives error when used together with the 5.0 EF ...
thenewseattle's user avatar
37 votes
1 answer
45k views

Entity Framework Code First Using Guid as Identity with another Identity Column

a.k.a How can we create multiple identity columns in Code First? Because of clustering performance, a common recommendation is to use an autoincremented integer column instead of a GUID created with ...
drzaus's user avatar
  • 24.6k
36 votes
1 answer
17k views

Where is the ExecuteStoreCommand method in Entity Framework 5?

I'm using EF5 in VS2012, and I trying to delete all data of some table using ExecuteStoreCommand, something like this: ctx.ExecuteStoreCommand("TRUNCATE TABLE [" + tableName + "]"); but the problem ...
qakmak's user avatar
  • 1,317

1
2 3 4 5
79