Use SQL Server view in NEW Azure App Service

流过昼夜 提交于 2019-11-29 16:15:16

You are pretty much right there. You need to just create a table controller to access the view. Ensure you have the system columns defined (version, updatedAt, createdAt, deleted and id). Also, ensure the right thing happens when you update the view (e.g. with an INSERT, UPDATE, DELETE) as that will tell you what needs to be done with the controller (for example, if you can't insert/update/delete, then make it read-only).

Reference blog post for you: https://shellmonger.com/2016/04/15/30-days-of-zumo-v2-azure-mobile-apps-day-8-table-controller-basics/

Things can be so easy sometimes ;-)

All I need to do is to write the following lines to my table controller:

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

Thanks for your help!

Had a similar issue but fixed it now, am using a .Net backend thou. 1. Log into azure portal and select the database you want to create the view in Then select the query Editor in the left pane. 2. Use the sql to create the query. 3.Create a table in the asp.net backend that matches your fields in your view. 4.Go to your asp.net backend and create a custom Api and write the following codes:

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
                }
            };
        }
     }

4.You edit my codes to select from your view. 5. Create a similar class in your mobile app that matches what u created in your backend. 5. You can then access your view by calling it in your mobile app with the following codes:

var users= await client.InvokeApiAsync<vwUser>("HelloCustom",HttpMethod.Get,null);

Thanks Guys. This is my fisrt answer to this beautiful community that carried me from day 1 of programming till now that am a bit conversant.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!