在什么情况下我需要使用CREATEREF,DEREF和REF关键字? [英] In what scenarios would I need to use the CREATEREF, DEREF and REF keywords?

查看:110
本文介绍了在什么情况下我需要使用CREATEREF,DEREF和REF关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于为什么我要使用上述关键字。我发现了大量的MSDN页面都介绍了如何。我正在寻找原因。

This question is about why I would use the above keywords. I've found plenty of MSDN pages that explain how. I'm looking for the why.

我要尝试写哪个查询意味着我需要它们?我问是因为发现的示例似乎可以通过其他方式实现...

What query would I be trying to write that means I need them? I ask because the examples I have found appear to be achievable in other ways...

为了自己弄清楚,我使用了一个非常简单的实体模型

To try and figure it out myself, I created a very simple entity model using the Employee and EmployeePayHistory tables from the AdventureWorks database.

我在网上看到的一个示例演示了类似于以下Entity SQL的示例:

One example I saw online demonstrated something similar to the following Entity SQL:

SELECT VALUE
    DEREF(CREATEREF(AdventureWorksEntities3.Employee, row(h.EmployeeID))).HireDate
FROM 
    AdventureWorksEntities3.EmployeePayHistory as h

这似乎取消了HireDate,而无需指定联接?

This seems to pull back the HireDate without having to specify a join?

为什么这比下面的SQL更好(看起来做的完全一样)?

Why is this better than the SQL below (that appears to do exactly the same thing)?

SELECT VALUE
    h.Employee.HireDate
FROM 
    AdventureWorksEntities3.EmployeePayHistory as h

看看上面的两个语句,我无法计算出额外的CRE ATEREF,DEREF位正在添加,因为我似乎可以在没有它们的情况下实现所需的功能。

Looking at the above two statements, I can't work out what extra the CREATEREF, DEREF bit is adding since I appear to be able to get at what I want without them.

我假设我只是没有找到能说明问题的方案。目的。我假设在某些情况下使用这些关键字要么更简单,要么是完成所需结果的唯一方法。

I'm assuming I have just not found the scenarios that demostrate the purpose. I'm assuming there are scenarios where using these keywords is either simpler or is the only way to accomplish the required result.

我找不到这些情况。 ...

What I can't find is the scenarios....

有人可以填补空白吗?我不需要整套SQL。我只需要一个起点即可,即一两个场景的简短描述...我可以自己扩展。

Can anyone fill in the gap? I don't need entire sets of SQL. I just need a starting point to play with i.e. a brief description of a scenario or two... I can expand on that myself.

推荐答案

TL; DR-REF / DEREF与C ++指针相似。它们是对持久实体的引用(不是未保存到数据源的实体)。

TL;DR - REF/DEREF are similar to C++ pointers. It they are references to persisted entities (not entities which have not be saved to a data source).

为什么要使用这样的东西?:对实体的引用与使用DEFEF(或扩展;或填充;或实例化)实体相比,使用的内存更少。如果您有一堆包含图像信息和图像数据(数据库中存储了4GB文件)的记录,这可能会派上用场。如果您不使用REF,并且为了获取图像元数据而撤回了其中的10个实体,那么您将很快填满您的内存。

Why would you use such a thing?: A reference to an entity uses less memory than having the DEFEF'ed (or expanded; or filled; or instantiated) entity. This may come in handy if you have a bunch of records that have image information and image data (4GB Files stored in the database). If you didn't use a REF, and you pulled back 10 of these entities just to get the image meta-data, then you'd quickly fill up your memory.

我知道,我知道。只需拉回查询中的元数据会更容易,但随后您就失去了REF对:-D

I know, I know. It'd be easier just to pull back the metadata in your query, but then you lose the point of what REF is good for :-D

这篇关于在什么情况下我需要使用CREATEREF,DEREF和REF关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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