惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - xqiwei

WCF RIA Services DomainService life-cycle and adding Transactions C#多线程 使用委托更新UI实例(WP7开发 其他线程中更新UI)(转载) Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) looping(and modifying) a collection - xqiwei LineBreak in a tooltip in xaml - xqiwei GetObjectbyKey in E.F. vs. Querying for a single entity Visual Studio集成开发环境无法启动调试 C#中关于String.Equals(object,object)和(object==object )的比较 - xqiwei - 博客园 IValueConverter 接口 ASP.NET页面生命周期和asp.net应用程序生命周期 Windows Presentation Foundation Tools and Controls ArcEngine开发之Command控件使用篇 Resharper进阶 C# 中的委托和事件 WPF系列文章 新技术文章 flash与javascript、asp.net(数据库)的交互 使用vs.net ajax实现幻灯片的效果 职业规划
Use GetObjectByKey() for better performance
xqiwei · 2010-09-06 · via 博客园 - xqiwei

When I want to fetch an entity, I normally have a method that uses a query.

image

This method will always query the database and you will have an up-to-date entity.

But if you need better performance perhaps GetObjectByKey() is a better option.

This method will check the cache first and returns the entity when it has been loaded already.

When it’s not in the cache, it would still query the database.

You need to supply an EntityKey(string qualifiedEntitySetName, string keyName, object keyValue)

I’ve made a generic method which automatically determines the entitySetName:

image

here’s an example of a call:

image

ps: I have hardcoded the keyName, because all my tables have an “ID” primary key.

When this is not the case, check out the CreateEntityKey method