ADO.NET实体框架的性能提示每个开发人员应该知道 [英] ADO.NET Entities Framework Performance Tips Every Developer Should Know

查看:100
本文介绍了ADO.NET实体框架的性能提示每个开发人员应该知道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有哪些表现提示每一个ADO.NET EF开发人员应该知道的?

What are the performance tips that every ADO.NET EF developer should know about?

请把每个尖端每回答,并解释为什么提示是不错的(例如,通过最大限度地减少数据库的往返)。

Please put each tip per answer and explain why the tip is good (e.g. by minimizing DB roundtrips).

推荐答案

使用的ObjectContext#GetObjectByKey()来检索,而不是使用他们的关键实体第一个()(或 FirstOrDefault )运算符在LINQ查询。后者将访问数据库,每次而前者将搜索EF缓存( ObjectStateManager 来具体)为实体第一次,也不会打的数据库,如果与实体指定键被找到。

Use ObjectContext#GetObjectByKey() to retrieve entities by their key instead of using First() (or FirstOrDefault) operator in the LINQ query. The latter will hit the database everytime while the former will search the EF cache (ObjectStateManager to be specific) for the entity first and won't hit the database if the entity with the specified key is found.

引用

  • <一个href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.getobjectbykey.aspx">MSDN在ObjectContext的#GetObjectByKey 文档
  • <一个href="http://www.thedatafarm.com/blog/2008/08/06/GetObjectbyKeyInEFVsQueryingForASingleEntity.aspx">GetObjectbyKey在E.F。与查询为一个单一的实体
  • MSDN documentation on ObjectContext#GetObjectByKey
  • GetObjectbyKey in E.F. vs. Querying for a single entity

这篇关于ADO.NET实体框架的性能提示每个开发人员应该知道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆