Skip to main content

Questions tagged [entity-framework-4]

A tag for ADO.NET Entity Framework 4.x, itself an object-relational mapping for the .NET framework.

entity-framework-4
Filter by
Sorted by
Tagged with
880 votes
29 answers
945k 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 ...
Luis Valencia's user avatar
802 votes
21 answers
689k views

There is already an open DataReader associated with this Command which must be closed first

I have this query and I get the error in this function: var accounts = from account in context.Accounts from guranteer in account.Gurantors select new AccountsReport ...
DotnetSparrow's user avatar
574 votes
18 answers
555k views

EF Migrations: Rollback last applied migration?

This looks like a really common task, but I can't find an easy way to do it. I want to undo the last applied migration. I would have expected a simple command, like PM> Update-Database -...
Cristian Diaconescu's user avatar
427 votes
20 answers
395k views

Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths - why?

I've been wrestling with this for a while and can't quite figure out what's happening. I have a Card entity which contains Sides (usually 2) - and both Cards and Sides have a Stage. I'm using EF ...
SB2055's user avatar
  • 12.6k
395 votes
10 answers
423k 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 ...
Halcyon's user avatar
  • 14.9k
266 votes
27 answers
269k views

The model backing the <Database> context has changed since the database was created

The error message : "The model backing the 'AddressBook' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an ...
Ashish Gupta's user avatar
  • 15.1k
252 votes
2 answers
106k views

What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First?

Does the virtual keyword has an effect when used on the properties in EF Code First?. Can someone describe all of its ramifications in different situations? For instance, I know it can control lazy ...
Scott Stafford's user avatar
244 votes
17 answers
334k views

How to update only one field using Entity Framework?

Here's the table Users UserId UserName Password EmailAddress and the code.. public void ChangePassword(int userId, string password){ //code to update the password.. }
h3n's user avatar
  • 5,228
231 votes
8 answers
255k views

The object 'DF__*' is dependent on column '*' - Changing int to double

Basically I got a table in my EF database with the following properties: public int Id { get; set; } public string Title { get; set; } public string Description { get; set; } public string Image { ...
Jordan Axe's user avatar
  • 3,903
220 votes
5 answers
108k 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.8k
190 votes
20 answers
261k views

Entity Framework: table without primary key

I have an existing DB with which I would like to build a new app using EF4.0 Some tables do not have primary keys defined so that when I create a new Entity Data Model, I get the following message: ...
Cris's user avatar
  • 12.2k
183 votes
2 answers
493k 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
183 votes
12 answers
48k views

Entity Framework 4 / POCO - Where to start? [closed]

I've been programming for a while and have used LINQ-To-SQL and LINQ-To-Entities before (although when using entities it has been on a Entity/Table 1-1 relationship - ie not much different than L2SQL) ...
Basic's user avatar
  • 26.6k
178 votes
4 answers
165k 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
171 votes
12 answers
96k views

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid

I have a one entity framework object and when I add it to my project, the connectionstring is added to app.config in the connectionstring section, but when I want to create new entitycontext and use ...
user421413's user avatar
  • 1,731
145 votes
8 answers
81k views

How to make Entity Framework Data Context Readonly

I need to expose an Entity Framework Data Context to 3rd party plugins. The purpose is to allow these plugins to fetch data only and not to let them issue inserts, updates or deletes or any other ...
Harindaka's user avatar
  • 4,828
141 votes
18 answers
150k views

Entity Framework - Invalid Column Name '*_ID"

I've narrowed this down to some issue between Code First and Database first EF, but I'm not sure how to fix it. I'll try to be as clear as I can, but I honestly am missing some of the understanding ...
Clarence Klopfstein's user avatar
135 votes
6 answers
93k views

Entity Framework 4 Single() vs First() vs FirstOrDefault()

I'm having a devil of a time finding a comparison of the different ways to query for a single item, and when to use each. Does anyone have a link that compares all these, or a quick explanation as to ...
asfsadf's user avatar
  • 3,842
135 votes
5 answers
97k views

Entity Framework 4 - AddObject vs Attach

I have been working with Entity Framework 4 recently, and am slightly confused as to when to use ObjectSet.Attach, and ObjectSet.AddObject. From my understanding: Use "Attach" when an Entity already ...
RPM1984's user avatar
  • 72.8k
132 votes
9 answers
93k views

LINQ to Entities case sensitive comparison

This isn't a case-sensitive comparison in LINQ to Entities: Thingies.First(t => t.Name == "ThingamaBob"); How can I achieve case sensitive comparison with LINQ to Entities?
Ronnie Overby's user avatar
130 votes
5 answers
130k views

How should I edit an Entity Framework connection string?

I recently had to edit my app.config file to change the connection string for an Entity Framework data model (.edmx file). But I'd like to know: Is there a way to edit the EF connection string using ...
DeveloperDan's user avatar
  • 4,674
128 votes
6 answers
72k views

EF Code First: How do I see 'EntityValidationErrors' property from the nuget package console?

I'm at a loss for this: I've defined my classes for a entity framework (4.1.3) code first approach. Everything was fine (I was creating the tables etc.) until I started to Seed. Now when I do the ...
jeremy's user avatar
  • 1,605
121 votes
2 answers
72k views

Entity Framework - Add Navigation Property Manually

I generated an Entity Framework Model (4.0) from my database. I did not design the database and do not have any control over the schema, but there are a few tables that do not have foreign key ...
Dismissile's user avatar
  • 32.9k
118 votes
13 answers
140k views

Entity framework self referencing loop detected [duplicate]

I have a strange error. I'm experimenting with a .NET 4.5 Web API, Entity Framework and MS SQL Server. I've already created the database and set up the correct primary and foreign keys and ...
Lydon's user avatar
  • 2,975
118 votes
10 answers
101k views

The object cannot be deleted because it was not found in the ObjectStateManager

I am getting this error "The object cannot be deleted because it was not found in the ObjectStateManager." My code is: protected MyEntities sqlEntities; public virtual void Delete(TEntity ...
Sami's user avatar
  • 3,976
113 votes
5 answers
28k views

How do I find a specific table in my EDMX model quickly?

I was wondering if anyone knows a quicker way to find a table in the EDMX model than just scrolling through the diagram and looking for the thing. Our database has around 50 tables in it and when I'm ...
monkeymindllc's user avatar
113 votes
17 answers
155k views

Why am I getting this error: No mapping specified for the following EntitySet/AssociationSet - Entity1?

I'm using Entity Framework 4 with the Model First approach. I started the project, designed the entities and generated the database. Everything worked fine. Then I needed to go back and add another ...
Andre Pena's user avatar
  • 58.5k
111 votes
5 answers
39k views

Update relationships when saving changes of EF4 POCO objects

Entity Framework 4, POCO objects and ASP.Net MVC2. I have a many to many relationship, lets say between BlogPost and Tag entities. This means that in my T4 generated POCO BlogPost class I have: ...
peterfoldi's user avatar
  • 7,471
110 votes
15 answers
90k views

A dependent property in a ReferentialConstraint is mapped to a store-generated column

I get this error when writing to the database: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'PaymentId'. public bool PayForItem(int terminalId, ...
Welsh King's user avatar
  • 3,198
99 votes
7 answers
90k views

How should I remove all elements in a DbSet?

What's the best way to remove all elements in a System.Data.Entity.DbSet, with Entity Framework 4.3?
aknuds1's user avatar
  • 67.4k
93 votes
3 answers
89k views

Using Include in Entity Framework 4 with lambda expressions

I've seen many articles about how to overcome this matter, all related to CTP4, Or adding my own extension methods. Is there an "official" EF4 included way to use lambda expressions inside include (...
Dani's user avatar
  • 14.9k
88 votes
4 answers
79k views

EF Including Other Entities (Generic Repository pattern)

I am using the Generic Repository pattern on top of Entity Framework Code First. Everything was working fine until I needed to include more entities in a query. I got to include one entity ...
Kassem's user avatar
  • 8,206
87 votes
16 answers
98k views

The mapping of CLR type to EDM type is ambiguous with EF 6 & 5?

Please any one can help me to fix this error? Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'City_DAL'. ...
Mahmoud Samir's user avatar
87 votes
5 answers
11k views

Reducing Repositories to Aggregate Roots

I currently have a repository for just about every table in the database and would like to further align myself with DDD by reducing them to aggregate roots only. Let’s assume that I have the ...
e36M3's user avatar
  • 6,002
85 votes
7 answers
142k views

The specified type member is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

var result = (from bd in context.tblBasicDetails from pd in context.tblPersonalDetails.Where(x => x.UserId == bd.UserId).DefaultIfEmpty() from opd in context.tblOtherPersonalDetails....
Sarang Amrutkar's user avatar
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
  • 24k
81 votes
8 answers
51k views

Why does the Contains() operator degrade Entity Framework's performance so dramatically?

UPDATE 3: According to this announcement, this has been addressed by the EF team in EF6 alpha 2. UPDATE 2: I've created a suggestion to fix this problem. To vote for it, go here. Consider a SQL ...
Mike's user avatar
  • 7,643
80 votes
4 answers
57k views

Better way to query a page of data and get total count in entity framework 4.1?

Currently when I need to run a query that will be used w/ paging I do it something like this: //Setup query (Typically much more complex) var q = ctx.People.Where(p=>p.Name.StartsWith("A")); //...
C.J.'s user avatar
  • 6,849
79 votes
10 answers
119k views

How to set CommandTimeout for DbContext?

I am looking a way to set CommandTimeout for DbContext. After searching I found the way by casting DbContext into ObjectContext and setting value for CommandTimeout property of objectContext. var ...
Yara's user avatar
  • 4,505
75 votes
4 answers
120k views

The result of a query cannot be enumerated more than once

I am using the entity framework (ef) and am getting the following error: "The result of a query cannot be enumerated more than once.". I have a repository class which contains the ef data context....
Halcyon's user avatar
  • 14.9k
74 votes
7 answers
240k views

LEFT JOIN in LINQ to entities?

I'm trying out LINQ to entities. I have a problem with the following: I want it to do this: SELECT T_Benutzer.BE_User ,T_Benutzer_Benutzergruppen.BEBG_BE FROM T_Benutzer LEFT JOIN ...
Stefan Steiger's user avatar
73 votes
6 answers
41k views

what is the most reasonable way to find out if entity is attached to dbContext or not?

when i try to attach entity to context i get an exception An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the ...
maxlego's user avatar
  • 4,894
72 votes
16 answers
54k views

EF4 - The selected stored procedure returns no columns

I have query in a stored procedure that calls some linked servers with some dynamic SQL. I understand that EF doesn't like that, so I specifically listed all the columns that would be returned. Yet, ...
cjbarth's user avatar
  • 4,391
72 votes
8 answers
64k views

Entity Framework 4 mapping fragment error when adding new entity scalar

I have an Entity Framework 4 model-first design. I create a first draft of my model in the designer and all was well. I compiled, generated database, etc. Later on I tried to add a string scalar (...
Jason Morse's user avatar
  • 6,284
70 votes
1 answer
53k views

How to include ampersand in connection string?

I'm using Entity Framework 4 for a simple app and would like to bake my connection credentials into the following connection string: <connectionStrings> <add name="MyEntities" ...
user403830's user avatar
67 votes
1 answer
25k views

Entity Framework mergeoption notracking bad performance

I have a strange behavior trying to execute a query declaring ObjectQuery MergeOption to "NoTracking", in this case entity framework should not attach any entity and not create the relative ...
MaRuf's user avatar
  • 1,864
66 votes
15 answers
59k views

Entity Framework Code First Fluent Api: Adding Indexes to columns

I'm running EF 4.2 CF and want to create indexes on certain columns in my POCO objects. As an example lets say we have this employee class: public class Employee { public int EmployeeID { get; set;...
Jim Wolff's user avatar
  • 5,160
62 votes
5 answers
82k views

Disable lazy loading by default in Entity Framework 4

It seems that lazy loading is enabled by default in EF4. At least, in my project, I can see that the value of dataContext.ContextOptions.LazyLoadingEnabled is true by default. I don't want lazy ...
Mike Chamberlain's user avatar
61 votes
8 answers
56k views

How to specify database name in Code First?

How do I tell EF what to name the database and where to put it? If there is no connection string in the Web.Config, it tries to put it in the local SQLEXPRESS Server, but I want to put it out on a ...
Sam's user avatar
  • 15.7k
61 votes
13 answers
106k views

Entity Framework Code First AddOrUpdate method insert Duplicate values

I have simple entity: public class Hall { [Key] public int Id {get; set;} public string Name [get; set;} } Then in the Seed method I use AddOrUpdate to populate table: var hall1 = new ...
Y.Yanavichus's user avatar
  • 2,417

1
2 3 4 5
148