本文介绍了Get< T>之间的差异负载< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Get<T>(object id)Load<T>(object id)有什么区别?该文档的内容大致相同.另外,如果有关系,在什么情况下我应该使用另一种方法?

What's the difference between Get<T>(object id) and Load<T>(object id)? The documentation pretty much reads the same. Also, if it matters, in what cases should I use one over the other?

推荐答案

提供的-get-load-and-querying-by.aspx"rel =" noreferrer>参考很清楚地解释了这一点.但是,主要区别在于,Load 不会命中数据库来检查和加载所需的实体,因为它假定您知道该实体存在. Load返回的对象是某种代理,可以在需要时延迟获取实际数据,或者在找不到该实体时引发异常.

The reference provided by Brian explains it quite clearly. However, the main difference is that Load doesn't hit the database to check and load the entity you require, since it assumes you know the entity exists. The object returned by Load is some kind of proxy that lazily fetches the real data when required or throws an exception if the entity is not found.

回顾:

Get命中数据库或会话高速缓存以检索实体数据.如果该实体存在,则返回它,否则将返回null.这是确定是否存在具有特定ID的实体的最安全方法.如果不确定使用什么,请使用Get.

Get hits the database or session cache to retrieve the entity data. If the entity exists it is returned, otherwise null will be returned. This is the safest way to determine whether an entity with a certain ID exists or not. If you're not sure what to use, use Get.

这篇关于Get&lt; T&gt;之间的差异负载&lt; T&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!