Edi Wang

.NET and Azure Developer

ADO.NET

Performance tips for Entity Framework

自从我用了EF,每次都很关心是否有潜在的性能问题。所以每次我写LINQ查询,都会使用SQL Profiler看一下实际生成的SQL语句,以便发现潜在的性能问题。也强烈建议大家这么去做,以免日后软件大了出了问题很难查。 一、只选择某列或某些列 有些时候,在C#里写LINQ虽然看着舒服,但性能不一定好,所以有必要做一些调整。比如这种情况: 我需要知道一篇文章的点击数,仅此而已,我可能会写: context.Post.FirstOrDefault(p => p.Id == postId).Hits; 或者: context.Post.Find(postId).Hits; 我期待着他们只去数据库里筛选Hits这一列的数据,然而,通过SQL Profiler会发现,这两条语句居然把全部列都给select出来了,访问Hits的操作实际是在内存中进行的。 虽然小表看不出性能问题,但万一你的表里有一列是存 …
C# ADO.NET Performance

How to Manually Upgrade Entity Framework 4.0 to 5.0

I have been working on the next version of my blog recently, and one of the updates is upgrading Entity Framework to version 5.0. When I initially set up the blog, I used EF4 that came with VS2010. The upgrade process from version 4.0 has to be done manually; using NuGet for the upgrade can only automatically update to versions 4.1 and above. Yesterday, I worked on it for a long time, and finally got the website up and running. Here's what I learned from the experience.
Entity Framework ADO.NET