何时以及如何使用查询结果 [英] When and how to use query results

查看:49
本文介绍了何时以及如何使用查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在何时可以访问查询结果以及如何访问查询时遇到了麻烦.似乎有几种方法可以访问结果,并且每种方法都有适当的用例.但是我还没有编写足够多的代码来知道哪个是哪个 随便.

I'm having trouble getting my mind around when I can access query results and how to access them. There seems to be several ways to access the results and each has an appropriate use case. But I haven't written enough diverse code yet to know which is which offhand.

这是我要开始工作的代码:

Here is the code I'm trying to get to work:

myapp.BrowseQuotes.created = function (screen) {
    msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {
        screen.RepUserName = PromiseResult;
        myapp.activeDataWorkspace.aris_dbData.RepByUserName()
            .execute().then(function (results) {
                var temp = results.results[0].RepFirm.RepFirmID;
            });
    });
};

我已经在查询设计器中创建了查询RepByUserName并将其添加到我的屏幕中.获取用户名后,将其分配给属性,执行查询,然后尝试访问结果.

I've created the query RepByUserName in the Query designer and added it to my screen. After I get the username, I assign it to a property, execute the query and then try to access the results.

如果我在尝试访问结果并查看Fiddler的行上放置一个断点,则结果可以很好地返回:

If I put a breakpoint on the line where I attempt to access the results and look at Fiddler, the results are being returned just fine:

但是,如果我尝试在Visual Studio中检查结果对象,它说它是未定义的.因此,当然,我要设置的变量和屏幕属性都是空白.

But if I try to inspect the results object in Visual Studio, it says it's undefined. And so, of course, my variables and screen properties I'm trying to set are all blank.

在这种情况下,我在做什么错?如果有人可以提供有关何时使用什么的表格,那也将有所帮助.我以为在阅读迈克尔·沃辛顿的书后,我了解了Query().execute()和getQuery()之间的区别,但是 我显然仍然缺少一些东西.

What am I doing wrong in this specific case? And if someone could provide a table as to when to use what, that would also be helpful. I thought I understood the difference between Query().execute() and getQuery() after reading Michael Washinton's book, but I'm clearly still missing something.

推荐答案

我认为问题在于数据最终会返回",但在您返回时不会返回期待它.

I think the problem is the data is returned 'eventually' but not when you're expecting it.

无论您身在何处,都有".then"这是一个"承诺 " (并且不保证它们会在您需要时执行并返回) 因此您有两个嵌套的Promises.有些人已经做到这一点,但我从来没有.这就是为什么在我的书中的章节中: 使用 在Visual Studio LightSwitch中实现的承诺 您会注意到,在该承诺中,我将只有一个LightSwitch Promise和一个JQuery调用,而没有另一个嵌套的LightSwitch Promise.

Everywhere you have a ".then" it is a "promise" (and they are not guaranteed to execute and return when you want them to) so you have two nested Promises.  Some have gotten this to work but I never have. That is why in my book, in the chapter: Using Promises In Visual Studio LightSwitch You'll notice I will have only one LightSwitch Promise and a JQuery call in that promise but not another nested LightSwitch Promise.

无论如何,我将使用 WCF RIA服务以显示信息.

Anyway, I would use a WCF RIA Service to display the information.


这篇关于何时以及如何使用查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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