Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Wayfast Datasets allow us to connect a page with a data source like a database or an API. Databases are one of the Wayfast Pillars. Wayfast Application Project’s are mostly used to interact with data sources and Datasets are the mean to achieve that goal. As a general rule we suggest using Stored Procedures to interact with databases but Datasets can run ad-hoc queries too.

...

Today we are going to review how to execute a store procedure for reading data and displaying it in a Grid.

Preconditions

Before we start, this lesson assumes the following preconditions:

  1. We already have a project connected with a database. You can find more details here: Attach or create databases. Let’s reuse our Hello World Project.

  2. We need an active requirement so we can create objects in our database.

  3. This lesson assumes you already know what a stored procedure is. If you don’t you can read about them here.

Step 1: Associate an instance

First let’s open Wayfast in a web browser and navigate to “Databases” menu then “Instances” submenu.

Here we can see a list of available SQL Server instances we can connect our project to.

Click on the “Associate Instance” button and a popup will be displayed.

Here we can select our development instance from the drop down and click on the “Submit” button.

The list of database instances associated to the project will be updated and now we are ready to create or attach a database.

Step 2: Create a database

Now we can navigate to “Database” submenu where we can see the list of databases related to this project.

Click on the “Create” button and a popup will be displayed.

Select an "Instance" and type the database name in the "Object Name".

In this case we are going to name it "HelloWorldDB".

We can add a comment to understand why we created this database in the future.

Let's type "DB created for training purposes".

And then click on the "Submit" button.

The list of databases will be updated indicating our DB was created successfully.

Step 3: Create database object and update Wayfast DB Model

First let’s Let’s connect to the project’s database using SQL Server Management Studio.

...

Once the popup closes all new database objects are available in wayfast.

Step 5: How to create a new Dataset? (IN REVIEW)

Go to “Project Pages” at the top menu . Select any of the pages available in the project. Then click on “New Dataset” button

...

A popup is displayed and we need to complete the mandatory fields.

...

One of the key details we need to understand about Datasets is the “Execution Type”. This field tells Wayfast when we want to execute this query. The first time we display the page, every time load the page or based on another control’s execution. This will impact the time it takes to load your page and how it is perceived by the end user. Let’s review this options in detail:

...

Execution Type

...

Description

...

Pre

...

Loads the dataset the first time the page is loaded. This option will increase the initial load but will prevent from calling loading this dataset many times which will improve page’s responsiveness.

...

Post

...

Loads the dataset on every postback. This means every time the page interacts with the server. This is the most expensive options but may be required in some scenario were your data is prone to change frequently.

...

On-demand

...

Runs upon another control’s action. For instance, you could use this option when you need to load the list of states based on the country selected on a dropdown.

In this example, we are going to select “Pre” so we can have our data refreshed only once.

After this, go to “Data Binding” tab. In this section, we can select the Stored Procedure we just created.

...

The “Add relationship” field allows to trigger this Dataset load based on a control’s event. We will review this specific case in the “Actions” lesson.

Let’s click on the “Submit” button to save the dataset and our Dataset will be available to be executed from other controls in this page.

...

and create a new page.

We are going to name it “HR_Roles_Screen”.

...

Click on the “Submit” button and access the page.

Expand the “Dataset” toggle button and click on the “New Dataset” button.

...

In the “New Dataset” popup let’s name it “HrRolesDataset“.

Select “Pre” option In “Execution Type” field. We are going to explain what this field is used for shortly.

...

Go to “Data Binding” tab and click on the magnifying glass icon at the right side of the “Stored procedure” field. A list of available stored procedures will be displayed.

...

Select our stored procedure and click on the “Submit” button.

Now our dataset will be displayed in the list.

...

Now that we have can retrieve data from our DB we need to show it in the Application’s UI.

...

How to connect a Dataset with a Grid?

Let’s create an example using grid columns linked to the new dataset.

...

All the information in the table is now available in the page. In the following lesson, we are going to analyze how we can insert values on the table using “Actions” feature.

Execution Types

One of the key details we need to understand about Datasets is the “Execution Type”. This field tells Wayfast when we want to execute this query. The first time we display the page, every time load the page or based on another control’s execution. This will impact the time it takes to load your page and how it is perceived by the end user. Let’s review this options in detail:

Execution Type

Description

Pre

Loads the dataset the first time the page is loaded. This option will increase the initial load but will prevent from calling loading this dataset many times which will improve page’s responsiveness.

Post

Loads the dataset on every post back. This means every time the page interacts with the server. This is the most expensive options but may be required in some scenario were your data is prone to change frequently.

On-demand

Runs upon another control’s action. For instance, you could use this option when you need to load the list of states based on the country selected on a dropdown.

In this example, we are going to select “Pre” so we can have our data refreshed only once.

Recap

In the first part, we learnt how Pages interact with database by creating Datasets. Then we made a first approach using SQL to create a simple Stored Procedure that was linked to Dataset. In the second part, we explained how the Controls under pages can display in different ways the information available on database, assigning the place and source. In the next lessons, we will learn how to connect the Controls with Actions that user will have in pages to make the application more dynamic.