Posts tagged Entity Framework
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.