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.
entity-framework-4.3
342
questions
350
votes
6
answers
306k
views
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 ...
281
votes
11
answers
180k
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 ...
174
votes
6
answers
94k
views
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,...
149
votes
6
answers
176k
views
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 ...
106
votes
2
answers
36k
views
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 ...
86
votes
5
answers
53k
views
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 ...
69
votes
9
answers
35k
views
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 ...
53
votes
10
answers
68k
views
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 ...
50
votes
4
answers
41k
views
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 ...
46
votes
3
answers
70k
views
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 '...
44
votes
5
answers
10k
views
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 ...
43
votes
3
answers
20k
views
Confusion over EF Auto Migrations and seeding - seeding every program start
I recently changed an application from using the following for dev:
DropCreateDatabaseIfModelChanges<Context>
To using:
public class MyDbMigrationsConfiguration: DbMigrationsConfiguration<...
41
votes
2
answers
26k
views
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 ...
40
votes
2
answers
16k
views
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 ...
39
votes
3
answers
61k
views
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 ...
37
votes
3
answers
15k
views
Entity Framework initialization is SLOW -- what can I do to bootstrap it faster?
My EF 4.3.1 model has 200-odd tables. Initial startup is horrible, several minutes. A DotTrace-captured profile implies some terrible algorithm/scalability choices deep in the framework, as ...
36
votes
3
answers
40k
views
How to fix: The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical?
I am using Entity Framework 4.3.1 against a SQL Server 2012 database and I am using the POCO approach. I am getting the following error and I am wondering if anyone can explain how to fix it:
...
35
votes
5
answers
22k
views
Linq when using GroupBy, Include is not working
include matchparticipants is not working. It always says Null when I debug.
But when I put the GroupBy in comment it works fine. I am using Entity framework 4.3.1 with code-first.
Entities:
public ...
34
votes
3
answers
16k
views
Entity framework 4.3 run migrations at application start
What is the best way to execute all required db migrations at application start with EF 4.3?
33
votes
3
answers
35k
views
Set Command Timeout in entity framework 4.3
I cannot find the a way to set the command timeout of a linq query using entity framework 4.3 and its' DbContext.
How do I increase Commandtimeout in entity framework?
EDIT
I am actually looking for ...
33
votes
1
answer
10k
views
Entity Framework 4.3 code first multiple many to many using the same tables
I have a model like
public class User
{
[Key]
public long UserId { get; set; }
[Required]
public String Nickname { get; set; }
public virtual ICollection<Town> Residencies ...
30
votes
4
answers
20k
views
Can anyone spot why I keep getting this error testing the EF 5 beta
Installed visual studio 11 beta as wanted to test EF 5 beta but keep hitting this an error.
Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(...
29
votes
6
answers
15k
views
How to add description to columns in Entity Framework 4.3 code first using migrations?
I'm using Entity Framework 4.3.1 code first with explicit migrations. How do I add descriptions for columns either in the entity configuration classes or the migrations, so that it ends up as the ...
28
votes
3
answers
62k
views
How to create database using code first migrations?
I'm having ASP.NET MVC 3 project that uses Entity Framwork 4.3 and its migrations. Now I want Entity Framework to create a database for me using migrations that I have already.
When I trying to run ...
26
votes
4
answers
25k
views
Why does Entity Framework's EF Migrations Add-Migration step require a database connection string?
I am trying to use and understand EF Migrations (using EF 4.3.1, Code First). In order to scaffold a new change, I have to use a command like this:
Add-Migration MyMigration
-ConnectionString "...
24
votes
4
answers
53k
views
Converting a LEFT OUTER JOIN to Entity Framework
Here is a SQL Query I want to convert to EF4.3
command = database.GetSqlStringCommand(@"
select
H.AUTHENTICATION_ID,
...
19
votes
4
answers
29k
views
Keyword not supported: 'metadata'.? with Sql Connection in Entityt Framework with MVC3
I am using Entity Framework 4 with my Asp.Net MVC3 application. My problem is that I am using Entity Framework to perform action with my database , That is working fine. For ...
19
votes
1
answer
12k
views
Entity Framework enumerating SqlQuery result
I have strange error while I am trying to view results of SqlQuery:
var sql = "SELECT @someParam";
var someParamSqlParameter = new SqlParameter("someParam", "Some Value");
var result = _dbContext....
19
votes
2
answers
19k
views
EF4.3.1 on .NET 4 - The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type
Update: Subject updated - this is now reproducible on EF 4.3.1 under .NET 4 running with VS2012 installed under Windows 8. Any ideas why this would start happening now?
The subject says it all really....
19
votes
2
answers
7k
views
Running update-database from Team City
I have created a new application using Entity Framework 4.3 database migrations. The migrations work great from the package manager console using the "update-database" command.
Now I want to run the ...
17
votes
4
answers
17k
views
Dynamic Include statements for eager loading in a query - EF 4.3.1
I have this method:
public CampaignCreative GetCampaignCreativeById(int id)
{
using (var db = GetContext())
{
return db.CampaignCreatives
...
16
votes
3
answers
45k
views
conversion of a datetime2 data type to a datetime data type error with EF Code first?
I'm using EF Code first with my asp.net mvc application.
here is my code:
Request.RequestDate = DateTime.Now;
the type of RequestDate is datetime in my database.
and this is error that occurred when ...
16
votes
3
answers
10k
views
Entity Framework Data Annotations equivalent of .WillCascadeOnDelete(false);
I'm currently using EF Code First 4.3 with migrations enabled, but automatic migrations disabled.
My question is simple, is there a data annotations equivalent of the model configuration ....
15
votes
1
answer
10k
views
EF 4.3 Migration - how to produce a downgrade script?
I have an issue which I could not find answer for across the web.
I am using CodeFirst EF 4.3.1 Migrations with MsSQL.
I have added several migrations and now I want to produce a script for upgrade/...
14
votes
4
answers
16k
views
How to create initializer to create and migrate mysql database?
I have been learning how to use EF for a week or so now and am stuck on the issue of creating/updating my database. I am able to create an initializer to create the database if it is not there:
...
14
votes
2
answers
1k
views
Visual Studio 2012 testing with csla and entity framework
In VS2010 my MSTest test run just fine.
When running in VS2012 I am getting an error. The test sets the Csla.ApplicationContext.User with a Custom Business Principal. When the EntityFramework is ...
13
votes
4
answers
14k
views
Entity Framework (4.3) looking for singular name instead of plural (when entity name ends with "s")
Here's my situation:
I have been working on an ASP.NET MVC 3 application for a while. It has a database (built out of a db project; I'm going db-first) for which I have an edmx model and then a set of ...
13
votes
2
answers
10k
views
Assembly Binding Old Reference Exception
I have been trying to solve an assembly binding issue for the last 12 hours, with not much luck. Last week, I had upgraded all of the projects in a solution from EF 4.1.0.0 to EF 4.3.1.0. I added ...
13
votes
1
answer
7k
views
Entity Framework Code First : How to map flat table to class with nested objects
I have the scenario where the data from a single table must be in 2 objects.
[Table]
-Field1
-Field2
-Field3
-Field4
And the class look like this:
[Class1]
-Field1
-Field2
-Class2 object here
[...
12
votes
3
answers
9k
views
Mixing Fluent API and DataAnnotations in EF code first
While we mostly use fluent configuration for our code-first POCOs, we have found it useful to use data annotations for things like the table name, PKs, etc. since it makes it easier for non-EF ...
12
votes
8
answers
8k
views
Entity splitting when key column has different names?
I'm using Entity Framework 4.3.1 Code-First and I need to split an entity between two tables. The tables have a primary key shared, and it is 1-to-1, but the columns are not named the same on each ...
12
votes
3
answers
3k
views
How can I unit test Entity Framework Code First Mappings?
I'm using Code First to map classes to an existing database. I need a way to unit test these mappings, which are a mix of convention-based, attribute-based, and fluent-api.
To unit test, I need to ...
11
votes
2
answers
5k
views
Generated Identifier Too Long For Constraint Name
I am just getting started with Entity Framework (4.3.1) and am making a code-first model with TPT inheritance using the MySQL EF provider (6.5.4). When attempting to create the database structure, I ...
11
votes
2
answers
16k
views
How can I disable the use of the __MigrationHistory table in Entity Framework 4.3 Code First?
I'm using Entity Framework 4.3 Code First with a custom database initializer like this:
public class MyContext : DbContext
{
public MyContext()
{
Database.SetInitializer(new ...
10
votes
1
answer
2k
views
How do OnModelCreating and non automatic Migrations relate?
When I add a new table that has some relations to my database and then run Add-Migration I see that code is generated in the Up method to add the table and its relations.
However, I prefer to define ...
10
votes
1
answer
7k
views
Is it always better to use 'DbContext' instead of 'ObjectContext'?
I just downloaded EntityFramework.dll v4.3. I've found a number of questions that compare DbContext vs. ObjectContext. But most of these are from 2010, or early 2011.
I'd like to read more on the ...
10
votes
1
answer
11k
views
1-to-1 relationship causing exception: AssociationSet is in the 'Deleted' state. Given multiplicity constraints
I have set up a 1-to-1 relationship using EF code first following the method prescribed here:
Unidirectional One-To-One relationship in Entity Framework
My mapping looks like this ...
protected ...
10
votes
1
answer
7k
views
How to affect the column order with Entity Framework Code First Migrations
I'm using Entity Framework 4.3 Code First and trying out the Migrations feature.
If I add a new property to my class and then run Add-Migration from the package manager console window I get something ...
10
votes
2
answers
391
views
code first auto gen proxy class navigation and collection properties are null
For all of my POCOs, the navigation and collection properties are all null.
Let me provide some background. I have a complex code first project using EF 4.3.1. Proxy generation was disabled. ...
9
votes
2
answers
15k
views
EF Code First cascade delete and update?
My entities are these:
public class Customer
{
public Customer()
{
Invoices = new List<Invoice>();
Payments = new List<Payment>();
}
public int ID { get; ...