Questions tagged [entity-framework-4.3]

Questions specific to version 4.3 of the ADO.NET Entity Framework, a feature of the .NET Framework 3.5 SP1 and higher.

Tag for specific version 4.3 of the ADO.NET Entity Framework, a feature of .NET 3.5 SP 1 and higher.

Generic questions should target the tag instead.

344 questions
330
votes
6 answers

What difference does .AsNoTracking() make?

I have a question regarding the .AsNoTracking() extension, as this is all quite new and quite confusing. I'm using a per-request context for a website. A lot of my entities don't change so don't need to be tracked, but I have the following scenario…
dotnetnoob
  • 10,783
  • 20
  • 57
  • 103
270
votes
11 answers

Entity Framework: One Database, Multiple DbContexts. Is this a bad idea?

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 break functional areas out into separate DbContext…
173
votes
5 answers

Entity Framework - Start Over - Undo/Rollback All Migrations

For some reason, my migrations appear to have been jumbled/corrupted/whatever. I'm at the point where I just want to start over, so is there a way to completely undo all migrations, erase the history, and delete the migration code, so I'm back to…
drzaus
  • 24,171
  • 16
  • 142
  • 201
147
votes
6 answers

Entity Framework code first unique column

I am using Entity Framework 4.3 and using Code Fist. I have a class public class User { public int UserId{get;set;} public string UserName{get;set;} } How do I tell Entity Framework that UserName has to be unique when creating database…
cpoDesign
  • 8,953
  • 13
  • 62
  • 106
106
votes
2 answers

How to seed data with AddOrUpdate with a complex key in EF 4.3

I am trying to seed a development database with some test data. I have used context.People.AddOrUpdate(p => p.Id, people)); with much success. I have another table that I need to seed, in which I would not know the primary key. For example, I would…
83
votes
5 answers

Entity Framework - Is there a way to automatically eager-load child entities without Include()?

Is there a way to decorate your POCO classes to automatically eager-load child entities without having to use Include() every time you load them? Say I have a Class Car, with Complex-typed Properties for Wheels, Doors, Engine, Bumper, Windows,…
68
votes
8 answers

How to manage Migrations in a project with multiple branches?

I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date. The project is under source-control and I have a number of branches. What I just realized is that there…
53
votes
10 answers

No connection string named 'MyApplicationEntities' could be found in the application config file

I just install EF 4.3 and trying to upgrade my project with migration. however I am getting issues with trying to execute add-migration initial to my project via Package Manager console. It is throwing any exception now No connection string named…
Sanj
  • 3,770
  • 6
  • 26
  • 31
47
votes
4 answers

EntityFramework Code First - Check if Entity is attached

I am trying to update an entity with a FK relationship in EntityFramework 4.3 Code First. I try to attach to the related entites by calling: Entry(item).State = EntityState.Unchanged I get the following exception: An object with the same key already…
Radu Negrila
  • 627
  • 1
  • 6
  • 11
45
votes
3 answers

Mapping a foreign key with a custom column name

I'm using Entity Framework 4.3 code-first with Oracle. I'm getting the following error: System.InvalidOperationException : The ForeignKeyAttribute on property 'WidgetSequence' on type 'WidgetDistributor.WidgetEntity' is not valid. The foreign key…
Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131
44
votes
5 answers

Code first DbMigrator causes error when building from different machines

We have a project under SCM. When I build it from my machine and publish to a remote server via msdeploy, everything works fine. When my colleague tries the same thing with the same project, freshly pulled from SCM, on the remote server entity…
spender
  • 117,338
  • 33
  • 229
  • 351
43
votes
3 answers

Confusion over EF Auto Migrations and seeding - seeding every program start

I recently changed an application from using the following for dev: DropCreateDatabaseIfModelChanges To using: public class MyDbMigrationsConfiguration: DbMigrationsConfiguration { public MyDbMigrationsConfiguration() …
41
votes
2 answers

Best way to incrementally seed data in Entity Framework 4.3

I have been using Entity Framework 4.3 on an existing database and I have a couple of scenarios that I am trying to cater for. Firstly, if I delete my database I would like to EF to recreate if from scratch - I have successfully used a…
40
votes
2 answers

How can I disable model compatibility checking in Entity Framework 4.3?

I'm working with EF 4.3 and have a context which needs to talk to a database which was generated by another library using EF Code First 4.3. The context is throwing an exception stating The model backing the 'Context' context has changed since…
STW
  • 44,917
  • 17
  • 105
  • 161
39
votes
3 answers

How to disable migration in Entity Framework 4.3.1?

Is there any way to disable migration in Entity Framework 4.3.1? I removed the migrations folder from the project and the generated tables in my database, but it doesn't work! How can you remove the migration?
amiry jd
  • 27,021
  • 30
  • 116
  • 215
1
2 3
22 23