Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在新Azure应用程序服务中使用SQL Server视图_Node.js_Cordova_Azure_Azure Mobile Services - Fatal编程技术网

Node.js 在新Azure应用程序服务中使用SQL Server视图

Node.js 在新Azure应用程序服务中使用SQL Server视图,node.js,cordova,azure,azure-mobile-services,Node.js,Cordova,Azure,Azure Mobile Services,我是Azure应用程序服务的新手 我在Azure数据库中创建了一个视图,用于跨多个表获取数据。现在我想使用Azure移动服务MobileService.GetTable在我的Cordova应用程序中使用此视图中的数据。。。。我在网上找到了几篇文章,描述了如何在经典的Azure门户中做到这一点。但是我需要一个新的Azure应用程序服务解决方案,它的后端是Node.js 作为Azure表从视图返回数据的语法是什么 var table = module.exports = require('azure

我是Azure应用程序服务的新手

我在Azure数据库中创建了一个视图,用于跨多个表获取数据。现在我想使用Azure移动服务MobileService.GetTable在我的Cordova应用程序中使用此视图中的数据。。。。我在网上找到了几篇文章,描述了如何在经典的Azure门户中做到这一点。但是我需要一个新的Azure应用程序服务解决方案,它的后端是Node.js

作为Azure表从视图返回数据的语法是什么

var table = module.exports = require('azure-mobile-apps').table();
table.read(function (context) {
// *** Need code to return data from sql view ***
//return context.execute();
});
在返回之前,最好使用一个参数来过滤视图中的数据

谢谢,
你说得很对。只需创建一个表控制器即可访问视图。确保已定义系统列version、updatedAt、createdAt、deleted和id。此外,确保在更新视图时发生正确的操作,例如使用INSERT、update、DELETE,因为这将告诉您需要对控制器执行哪些操作。例如,如果无法插入/更新/删除,则将其设置为只读


为你参考博客帖子:

有时候事情会很容易-

我需要做的就是将以下行写入我的表控制器:

var table = require('azure-mobile-apps').table();
table.databaseTableName = 'ViewName';
module.exports = table;

谢谢你的帮助

有一个类似的问题,但现在已经解决了,我使用的是.Net后端。 1.登录azure portal并选择要在其中创建视图的数据库,然后在左侧窗格中选择查询编辑器。 2.使用sql创建查询。 3.在asp.net后端中创建与视图中的字段匹配的表。 4.转到asp.net后端,创建自定义Api并编写以下代码:

public class HelloCustomController : ApiController
{
    MobileServiceContext context;
    public HelloCustomController()
    {
        context = new MobileServiceContext();
    }

    [HttpGet]
    public async Task<List<vwUser>> Get()
    {
        try
        {
            var users = context.Database.SqlQuery<vwUser>("Select * from 
             dbo.vwUser);
            return await users.ToListAsync();
        }
        catch(Exception ex)
        {
            return new List<vwUser>()
            {
                new vwUser
                {
                    UserName=ex.Message
                }
            };
        }
     }
var users= await client.InvokeApiAsync<vwUser>("HelloCustom",HttpMethod.Get,null);
4.编辑我的代码以从视图中选择。 5.在您的移动应用程序中创建一个类似的类,该类与您在后端创建的类相匹配。 5.然后,您可以使用以下代码在移动应用程序中调用视图来访问视图:

public class HelloCustomController : ApiController
{
    MobileServiceContext context;
    public HelloCustomController()
    {
        context = new MobileServiceContext();
    }

    [HttpGet]
    public async Task<List<vwUser>> Get()
    {
        try
        {
            var users = context.Database.SqlQuery<vwUser>("Select * from 
             dbo.vwUser);
            return await users.ToListAsync();
        }
        catch(Exception ex)
        {
            return new List<vwUser>()
            {
                new vwUser
                {
                    UserName=ex.Message
                }
            };
        }
     }
var users= await client.InvokeApiAsync<vwUser>("HelloCustom",HttpMethod.Get,null);

谢谢各位。这是我对这个美丽社区的第一个回答,从编程的第一天到现在,我对这个社区有点熟悉。

嗨,阿德里安。谢谢你的快速回答和你的博客。我将系统列添加到我的视图版本、updatedAt、createdAt、deleted和id中。但我无法弄清楚如何从表控制器中的sql视图获取数据。能否提供一个从数据库视图而不是数据库表返回数据的表控制器示例?再次感谢你,UweHey,你能详细说明一下你是如何解决这个问题的吗?我正在努力完成同样的事情。我创建了一个视图MyView和一个EasyTable ViewController,但我不确定代码放在哪里。就像这篇文章中的代码一样-这是app.js还是ViewController.js中的代码?