entity-framework

Reattaching an object graph to an EntityContext: "cannot track multiple objects with the same key"

Can EF really be this bad? Maybe... Let's say I have a fully loaded, disconnected object graph that looks like this: myReport = {Report} {ReportEdit {User: "JohnDoe"}} {ReportEdit {User: "JohnDoe"}} Basically a report with 2 edits that were done by the same user. And then I do this: EntityContext.Attach(myReport); InvalidOpera...

Using MVC2 to update an Entity Framework v4 object with foreign keys fails

With the following simple relational database structure: An Order has one or more OrderItems, and each OrderItem has one OrderItemStatus. Entity Framework v4 is used to communicate with the database and entities have been generated from this schema. The Entities connection happens to be called EnumTestEntities in the example. The trim...

entity framework client connection details versus connection details in EF library?

Hi, I have an EF project which has embedded connection details. Then when I use this project from a client library I get told to copy the config file across, which includes the connection details. What are the rules re which connection string would be used here? i.e. does the database connection string in the client project override ...

how can I swap Entity Framework connection strings easily when I test on different servers (i.e. different databases)

how can I swap Entity Framework connection strings easily when I test on different servers (i.e. different databases) - at the moment it is a bit tedious going into the design parameters and trying to swap back and forth each time I change. ...

Error reached after genereated entity framework classes by edmgen tool

Hello, First I read this question, but this knowledge did not help to solve my problems. In initial I've created edmx file by Visual Studio. Generated files with names: uqsModel.Designer.cs uqsModel.edmx This files are located on App_Code folder. And my web app work normally. In Web Config generated connectionstring automatically...

Ignore records marked as deleted in navigation properties in EF 4.0

Hi, I have added a column 'IsDeleted' to every entity in my Entity Framework 4.0 model and implemented an Interface for it. How can i accomplish that the entities with 'IsDeleted' set to 'true' are ignored by all Objectsets and Navigationproperties in my model? Filtering the result using LinQ does not work i think, because the result ca...

Persisting details in Master Detail relation EF4 POCO

Scenario: Entity Framework 4 , POCO templates and Master Detail relation. Lets say I have a master type like this: //partial implementation of master entity partial class Master { public void AddDetail(x,y,z) { var detail = new Detail() { X = x, Y = y, Z = z, }; ...

Entity Framework vs. nHibernate for Performance, Learning Curve overall features

I know this has been asked several times and I have read all the posts as well but they all are very old. And considering there have been advancements in versions and releases, I am hoping there might be fresh views. We are building a new application on ASP.NET MVC and need to finalize on an ORM tool. We have never used ORM before and h...

Get top N records using LINQ to Entities

Hi all, I am using Linq to entities and would like to know if I can get a limited number of records when i query. I just need the top N records as the query do the orderby and other clauses. Is this possible or I will have to get the top N using foreach loop? Thanks in advance for Ideas and suggestions, Abdel Olakara ...

How to save in Hindi in database using MVC application

I have a MVC application and using the entity framework model for MYSQL database. I what to save hindi text in database. When I using the hindi text then it is showing ?? in database. I am using ckeditor to enter the text How can I save the hindi text.I have also changed the collation to utf-8. Thanks supriya ...

Multiple databases in one project - Entity framework (self tracking entities)

In my project, I want to have access to 2 different databases. I created two .edmx files in the same project, added the self tracking entities T4 thingie, and kaboom :) Does not work anymore. I get a looooooot of ambiguity errors (ObjectChangeTracker and such) What would be the preferred solution here? I can delete the duplicate conte...

How to handle Foreign Keys with Entity Framework

I have two entities. Groups. Pools. A Group can create many pools. So I setup my Pool table to have a GroupID foreign key. My code: using (entity _db = new entity()) { Pool p = new Pool(); p.Name = "test"; p.Group.ID = "5"; _db.AddToPool(p); } This doesn't work. I get a null reference exception on p.Group...

Entity Framework 4 POCO entities in separate assembly, Dynamic Data Website?

Basically I want to use a dynamic data website to maintain data in an EF4 model where the entities are in their own assembly. Model and context are in another assembly. I tried this http://stackoverflow.com/questions/2282916/entity-framework-4-self-tracking-entities-asp-net-dynamic-data-error but get an "ambiguous match" error from ref...

Global Entity Framework Context in WPF Application

Good day, I am in the middle of development of a WPF application that is using Entity Framework (.NET 3.5). It accesses the entities in several places throughout. I am worried about consistency throughout the application in regard to the entities. Should I be instancing separate contexts in my different views, or should I (and is a a...

Using FluentValidation with Castle Windsor and Entity Framework 4.0 (POCO) in MVC2

This isn't a very simple question, but hopefully someone has run across it. I am trying to get the following things working together: MVC2 FluentValidation Entity Framework 4.0 (POCO) Castle Windsor I've pretty much gotten everything working. I have Castle Windsor implemented and working with the Controllers being served up by the ...

EF4. Add a object with relationship causes full table select

Ex 1: "autor.ComentariosWorkItens.Add(comentarioWorkItem);" autor.ComentariosWorkItens makes EF4 load all ComentariosWorkItens. Ex 2: comentarioWorkItem.Usuario = autor; Fixup make EF load all ComentariosWorkItens too: private void FixupUsuario(Usuario previousValue) { if (previousValue != null && previousValue.Come...

C# Entity FrameWork MySQL Slow Queries Count()

Hello, I'm having a serious issue with MySQL and Entity Framework 4.0. I have dropped a Table onto the EF Designer surface, and everything seems OK. However, when I perform a query in the following fashion: using(entityContext dc = new entityContext()) { int numRows = dc.myTable.Count(); } The query that is generated looks someth...

how to use Settings.settings for entity framework connection strings?

I'd like to store the Entity model connection string in the app.config using the same approach used by old Typed DataSet. Both use the same section: <connectionStrings>. Entity saves the connection as: <add name="MyDB_Entities" connectionString="metadata=res://*/MyDB.csdl|res:......" providerName="System.Data.EntityClient" /> Typed Da...

what is the best practice approach for n-tier application development with entity framework?

I am building an application using entity framework. I am using the T4 template to generate self tracking entities. Currently, I am thinking of creating the entity framework code in a separate project. In this same project, I would have partial classes with additional methods for the entities. I am thinking of creating a separate proje...

How do I delete a child entity from a parent collection with Entity Framework 4?

I'm using Entity Framework 4 and have a one-to-many relationship between a parent and child entity. I'm trying to delete a child using the parent repository by removing it from the parent's children collection: public virtual void RemoveChild(Child child) { children.Remove(child); } When I try to save the c...