Questions tagged [entity-framework-5]

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

What’s New in EF5 (from ADO.NET team blog)

EF 5 includes a number of new features and bug fixes to the EF4.3 release. Most of the new features are only available in applications targeting .NET 4.5, see the Compatibility section for more details.

  • Enum support allows you to have enum properties in your entity classes.
  • Spatial data types can now be exposed in your model using the DbGeography and DbGeometry types.
  • The Performance enhancements that we recently blogged about.
  • Code First will now detect if you have LocalDb or SQL Express available for creating new databases. Visual Studio 2012 includes LocalDb, whereas Visual Studio 2010 includes SQL Express.
  • Code First will add tables to existing database if the target database doesn’t contain any of the tables from the model.

The EF Designer in Visual Studio 2012 also has some new features:

  • DbContext code generation for new models means that any new models created using the EF Designer will generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed. Existing models will not automatically change to DbContext code generation.
  • Multiple-diagrams per model allows you to have several diagrams that visualize subsections of your overall model. Shapes on the design surface can also have coloring applied.
  • Table-Valued functions in an existing database can now be added to your model.
  • Batch import of stored procedures allows multiple stored procedures to be added to the model during model creation.

See for more information.

3942 questions
896
votes
9 answers

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. I have found three methods to which I'll mention…
Stokedout
  • 11,003
  • 5
  • 24
  • 30
294
votes
8 answers

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() { CalculationViewModel calculationViewModel =…
user547794
  • 14,263
  • 36
  • 103
  • 152
218
votes
5 answers

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's the technical difference(s) of those 3 methods?…
193
votes
7 answers

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.Modules.Select(s => s.Chapters)) .Single(x…
AnimaSola
  • 7,146
  • 14
  • 43
  • 62
176
votes
2 answers

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, c => c.EID, cm => cm.EID, …
176
votes
4 answers

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 { // Partial list of properties public…
171
votes
9 answers

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 them. That isn't what I wanted so I pretty much had…
156
votes
7 answers

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 Manager Console to update the database using…
142
votes
12 answers

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 the .mdf file, the following exception is thrown…
140
votes
28 answers

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 not recognized as the name of a cmdlet, function,…
131
votes
6 answers

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 console (Visual Studio 2012), there's an error…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
121
votes
12 answers

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 version 11.0.0.0 I have tried to install…
NoWar
  • 36,338
  • 80
  • 323
  • 498
119
votes
5 answers

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 queries are not warmed-up, so called cold queries. I…
user1372494
115
votes
7 answers

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 solution with others in case they have the same…
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
103
votes
7 answers

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 { [Key] public int UserID { get; set; } …
1
2 3
99 100