locked
execute query in html client? RRS feed

  • Question

  • hi!

    i'm trying to figure can i (and how) to execute query on client, in desktop client something like this:

    Private Sub Kreiraj_korisnika_Execute()
                Dim res = Me.DataWorkspace.ApplicationUserData.CreateAppUser(Me.Novi_korisnik, Me.Novi_password, Me.Novo_puno_ime)
                ShowMessageBox(res.Id.ToString & vbCrLf & res.UserName & vbCrLf & res.FullName)
            End Sub

    can this be done in html client?

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, March 11, 2013 11:12 PM

Answers

  • Hi Kivito,

    In theory the Intellisense should help, but the JavaScript Intellisense Engine in Visual Studio tends to have issues when dealing with large code files.

    Here's a quick overview:

    - The root of the client's data context should be a data workspace. You can access a data workspace by either using screen.details.dataWorkspace or myapp.activeDataWorkspace.

    - Data Workspace should have properties representing the Data Services you have in the application.

    - Each Data Service should have properties representing the Entity Sets it has. For example dataWorkspace.Northwind.Customers.

    - To load an Entity Set, you use load method. For example dataWorkspace.Northwind.Customers.load.

    - You can build up additional queries from an Entity Set using skip, top, orderBy, thenBy, etc. Everytime you invoke one of these query operation, it returns a query.

    - You execute a query, you use execute method. For example dataWorkspace.Northwind.Customers.top(10).execute.

    - Both Entity Set load and Query execute returns a Promise object, which represents the async operation. To handle the callbacks, you invoke then method on the Promise object and pass in two functions, one for success and one for failure. For example

    dataWorkspace.Northwind.Customers
        .top(10).execute()
        .then(function (result) {
        }, function (error){
        });

    You're heading to the right direction already.

    Best regards,
    Huy Nguyen

    • Marked as answer by Kivito Wednesday, March 13, 2013 7:02 PM
    Wednesday, March 13, 2013 4:50 PM

All replies

  • Hi,

    Yes, it can be done on HTML Client, the syntax is a little bit different. For example the following code loads 30 Customers starting from the 11th Customer, order by "CompanyName".

        screen.details.dataWorkspace
            .ApplicationData.Customers
            .skip(10)
            .top(30)
            .orderBy("CompanyName")
            .execute(function succeed(result) {
                var customers = result.results;
            }, function fail(error) {
            });

    Queries also support filter operation, the format can be found at OData spec here.

    Best regards,
    Huy Nguyen


    Tuesday, March 12, 2013 4:28 PM
  • hi Huy!

    i've managed to work with this syntax:

    var at = myapp.activeDataWorkspace.TN_Data.ArtikalPoSifri(str).execute();
        at.then(function (value) {
            var art = value.results[0];
        }, function (error) {
            alert(error)
        });
     

    but i'm little confused when to use specific syntax (i'm new to javascript), by using your example i was getting syntax error when function was executed, also i noticed that for specific queries i have execute() methods, but for dataworkspace collections, there is no execute() and it seems that usage is little different, is there a difference when query is set-up to return just one result?

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Wednesday, March 13, 2013 7:04 AM
  • Hi Kivito,

    In theory the Intellisense should help, but the JavaScript Intellisense Engine in Visual Studio tends to have issues when dealing with large code files.

    Here's a quick overview:

    - The root of the client's data context should be a data workspace. You can access a data workspace by either using screen.details.dataWorkspace or myapp.activeDataWorkspace.

    - Data Workspace should have properties representing the Data Services you have in the application.

    - Each Data Service should have properties representing the Entity Sets it has. For example dataWorkspace.Northwind.Customers.

    - To load an Entity Set, you use load method. For example dataWorkspace.Northwind.Customers.load.

    - You can build up additional queries from an Entity Set using skip, top, orderBy, thenBy, etc. Everytime you invoke one of these query operation, it returns a query.

    - You execute a query, you use execute method. For example dataWorkspace.Northwind.Customers.top(10).execute.

    - Both Entity Set load and Query execute returns a Promise object, which represents the async operation. To handle the callbacks, you invoke then method on the Promise object and pass in two functions, one for success and one for failure. For example

    dataWorkspace.Northwind.Customers
        .top(10).execute()
        .then(function (result) {
        }, function (error){
        });

    You're heading to the right direction already.

    Best regards,
    Huy Nguyen

    • Marked as answer by Kivito Wednesday, March 13, 2013 7:02 PM
    Wednesday, March 13, 2013 4:50 PM
  • hi Huy,

    your quick overview really helps and clears some things/doubts..

    but more questions coming, so be prepared.. ;)

    thanks again and cheers!

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Wednesday, March 13, 2013 7:02 PM