Whenever I tried opened the Entity Framework’s edmx file, Visual Studio 2008 would simply close. I tried to google, stack overflow. But couldn’t find the answer.
I noticed that when I double clicked on the edmx file, the status bar said “Initializing toolbox” just before closing of Visual Studio.
- Close all the open windows using the Window->Windows menu in Visual Studio
- Explicitly click on the “Toolbox” pane. From the menu you would choose View->Toolbox.
- Then double click on .edmx to open it. You should be able to open it successfully.
I still unsure whether .edmx opened because I closed all the windows or because I opened the Toolbox explicitly.
I received this error when opening an edmx file in my ASP.Net MVC 3 project. Spent several hours to figure out. Another related problem I had was that the “ADO.Net Entity Data Model” project template did not appear when adding new item to the project. Spent several hours finding a solution & finally found it here: http://stackoverflow.com/questions/5696436/no-entity-data-model-edmx-template-with-visual-studio-2010-sp1-ado-net-entit
Installing “ADO.NET Entity Framework Tools” from Visual Studio 2010 media solved both the problems mentioned above.
I had a list of tags for a particular user. I wanted to show only unique tags. I initially thought there would be something an inbuilt ‘distinct’ operator in Linq. Unfortunately not. I then discovered the Distinct() function. But it doesn’t support filtering the results by a particular column.
Thanks to this StackOverflow question that set my direction. It says that I must use the ‘group by’ operator, which I did.
Following is the code that I ended up with:
1 2 3 4 5
//distinct tags for a particular user var tags = from t in _db.Tags where t.UserId == userId group t by t.Name into g select g.FirstOrDefault();
Since the query returns a group, we must select the first item in the group. Hence FirstOrDefault().
I was happily working with Entity Framework 1 until I read at several places about its lack of important features that are normally expected from an ORM framework. I started thinking seriously about upgrading to Entity Framework 4 (yes, the next version after Entity Framework 1) after I read this No Confidence letter. It lists all the issues that EF1 has and also suggests improvements. Several architects signed it.
So I upgraded to Entity Framework 4. This required me to upgrade my projects to Visual Studio 2010 & .Net Framework 4. Along with this, I also upgrade my MVC 2 project to MVC 3 with the help of this article.
Although POCO & Persistence Ignorance are the two most-liked features, they did not interest me because I had already generated the Entity classes from the database in EF1 and mapped them to my own model. What interested me was Lazy Loading and Foreign key association.
Entity Framework 4 addresses several issues and it has undergone a major rework. Worth upgrading.