ASP.NET MVC – Attaching an entity of type ‘MODELNAME’ failed because another entity of the same type already has the same primary key value

Problem SOLVED! Attach method could potentially help somebody but it wouldn’t help in this situation as the document was already being tracked while being loaded in Edit GET controller function. Attach would throw exactly the same error. The issue I encounter here was caused by function canUserAccessA() which loads the A entity before updating the … Read more

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

Because Stage is required, all one-to-many relationships where Stage is involved will have cascading delete enabled by default. It means, if you delete a Stage entity the delete will cascade directly to Side the delete will cascade directly to Card and because Card and Side have a required one-to-many relationship with cascading delete enabled by … Read more

Create code first, many to many, with additional fields in association table

It’s not possible to create a many-to-many relationship with a customized join table. In a many-to-many relationship EF manages the join table internally and hidden. It’s a table without an Entity class in your model. To work with such a join table with additional properties you will have to create actually two one-to-many relationships. It … Read more

ASP.NET MVC 2.0 Implementation of searching in jqgrid

Probably you have problem on the server side. Could you append your question with the code of DynamicGridData action which you currently use. The action should have filters as the parameter. Some parts of your current code are definitively wrong. For example jqGrid is the jQuery plugin. So the methods of jQuery will be extended … Read more

Entity Framework and Connection Pooling

Connection pooling is handled as in any other ADO.NET application. Entity connection still uses traditional database connection with traditional connection string. I believe you can turn off connnection pooling in connection string if you don’t want to use it. (read more about SQL Server Connection Pooling (ADO.NET)) Never ever use global context. ObjectContext internally implements … Read more