---
title: Load a sample of the source in development
description: Limit the rows each Stage reads in development with a custom property and a template module that adds SELECT TOP to the Stage source view.
---

[Skip to content](https://knowledge.bigenius-x.com/load-a-sample-of-the-source-in-development#main-content)

[Contact us](https://knowledge.bigenius-x.com/kb-tickets/new?hsLang=en) [Go to Customer Portal](https://knowledge.bigenius-x.com/customer-portal?hsLang=en)

[![TRI\_Logo\_biGENIUS\_2020\_RGB\_s](https://knowledge.bigenius-x.com/hs-fs/hubfs/Marketing/TRI_Logo_biGENIUS_2020_RGB_s.png?width=150&height=42&name=TRI_Logo_biGENIUS_2020_RGB_s.png)](https://www.bigenius-x.com/)

Open main navigation

Close main navigation

- [Contact us](https://knowledge.bigenius-x.com/kb-tickets/new)
- [Go to Customer Portal](https://knowledge.bigenius-x.com/customer-portal)

 How can we help you?

- There are no suggestions because the search field is empty.

1. [biGENIUS-X Knowledge Base](https://knowledge.bigenius-x.com/?hsLang=en)
2. [Best practices](https://knowledge.bigenius-x.com/best-practices?hsLang=en)
3. [Use Cases](https://knowledge.bigenius-x.com/best-practices?hsLang=en#use-cases)

# Load a sample of the source in development

**Applies to**  
Platform: Microsoft SQL Server  
License: Enterprise

A template module can replace the Stage source view, so that a Stage reads only part of the rows of its source. A custom property on the Stage sets the number of rows per model object. Use it in development when the source is too large to load in full.

The template module replaces the whole view of every Stage it applies to, also of a Stage without a value, which then reads all rows. The code covers simple Stages only, see [Limits of the code](https://knowledge.bigenius-x.com/load-a-sample-of-the-source-in-development#limits-of-the-code), so apply it only to the Stages that need a sample. The code in this article writes Microsoft SQL Server code for Stages of the Microsoft SQL Server Stage configuration, not of Stage Files or Stage OpenQuery. For another platform, start from the generated Stage source view of that platform and use its row limit.

### Prerequisites

- A project with Stage model objects and a development branch that you can change.
- The permission Manage advanced settings, see [Understand the Advanced Settings overview](https://knowledge.bigenius-x.com/understand-the-advanced-settings-overview?hsLang=en).
- Custom properties and template modules in your license, see [Manage Custom Properties](https://knowledge.bigenius-x.com/manage-custom-properties?hsLang=en) and [Manage Template Modules](https://knowledge.bigenius-x.com/manage-template-modules?hsLang=en).

The template module, the custom property and its values are stored in the branch, so a merge carries them into the target branch. A test or production load from that branch then reads only the sample, and delete detection in a later model object can mark the rows outside the sample as deleted, see [Configure delete detection](https://knowledge.bigenius-x.com/configure-a-delete-detection-behavior?hsLang=en). Keep the development branch out of merges. If you merge it, delete the template module and clear **SelectTopValue** first. Clearing the value alone is not enough: the template module still replaces the view with its simplified code. Before you generate for test or production, check in **Show as Code** that the StageSourceView part is the generated view again, for example with `COLLATE DATABASE_DEFAULT` on the string columns and without `SELECT TOP`.

### Create the custom property SelectTopValue

1. Open **Project Settings** and choose **Advanced Settings**.
2. Choose **Custom Properties**, stay on the **Model Object** tab and choose the plus icon. **Create new Custom Property** opens.
3. Enter `SelectTopValue` in **Name**, select `Implementation` in **Property Group**, `Stage` in **Model Object Type** and `Single Line String` in **Type**, and save. The property appears in the list of the **Model Object** tab.  
   ![Create new Custom Property with Name SelectTopValue, Property Group Implementation, Model Object Type Stage, Type Single Line String and an empty Default Value](https://knowledge.bigenius-x.com/hs-fs/hubfs/knowledge_base_screenshots/avoid-to-load-all-data-in-development-custom-property.png?width=620&height=420&name=avoid-to-load-all-data-in-development-custom-property.png)

[Create a Custom Property](https://knowledge.bigenius-x.com/create-a-custom-property?hsLang=en) describes every field.

### Create the template module

1. Open **Manage Term Mappings** of one Stage and choose **Show as Code**. Note the placeholders in the StageSourceView part: the schema of the Stage layer and the server, database and schema of the source system.
2. In **Advanced Settings**, choose **Edit Template Modules** and the plus icon. **Create new Template** opens.
3. Keep `Replace Template` in **Template Type**, select `Stage` in **Model Object Type** and `Stage Source View` in **Part per Model Object Type**.
4. Select the Stages that need a sample in the list, only Stages of the source system whose placeholders you noted in step 1. Leave **Use for all future Model Objects** cleared, so that new Stages keep the generated view.
5. Replace the code in the editor with the code of [Template module code](https://knowledge.bigenius-x.com/load-a-sample-of-the-source-in-development#template-module-code), and replace the four placeholders in parts A and B with those of step 1.
6. Choose **Validate**. The **Error list** stays empty.
7. Save. The template module appears in the list with the model objects it applies to.

Part A of the code holds the placeholders of one source system. For the Stages of another source system, create one more template module with the placeholders of that source system. Its list shows only the Stages that no other template module of this part replaces. [Create a Template Module](https://knowledge.bigenius-x.com/create-a-template-module?hsLang=en) describes every field.

### Set the number of rows

1. Open **Edit Model Object** of a Stage.
2. In the **Implementation** group, enter the number of rows in **SelectTopValue**, for example `1000`, and save.

Enter a positive whole number. The code writes the value into the view as it is, so other text makes the view invalid, which shows only at deployment. Leave **SelectTopValue** empty for a Stage that reads all rows.

### Template module code

The code was validated with Generator 2.4. The placeholders in parts A and B come from a project with the Project Identifier `dimensional.mssql` and the source system `bfmmssql`:

```
using biGENIUS.ArchitectureModel.Domain;
namespace CustomTemplate
{
  public class Executor
  {
    public void WriteOutput(TargetObject targetObject, ITemplateContextV2 templateContext)
    {
      //A: Source placeholders
      var sourceServer = "{dimensional.mssql#bfmmssql#server_name}";
      var sourceDatabase = "{dimensional.mssql#bfmmssql#database_name}";
      var sourceSchema = "{dimensional.mssql#bfmmssql#schema_name}";

      //B: Target placeholder
      var targetSchema = "{dimensional.mssql#stage#schema_name}";

      //C: Alias and ID of the source model object
      var alias = "";
      var sourceModelObjectId = "";
      foreach (var dataflow in targetObject.Dataflows)
      {
        foreach (var dataflowSet in dataflow.DataflowSets)
        {
          foreach (var dataflowSetObject in dataflowSet.DataflowSetObjects)
          {
            alias = dataflowSetObject.Alias;
            sourceModelObjectId = dataflowSetObject.SourceModelObjectId.ToString();
          }
        }
      }

      //D: Name of the source model object
      var source = "";
      foreach (var modelObject in templateContext.ArchitectureModel.ModelObjects)
      {
        if (modelObject.Id.ToString() == sourceModelObjectId)
        {
          source = modelObject.Name;
        }
      }

      //E: Value of the custom property SelectTopValue
      var selectTopValue = targetObject.GetPropertyValue("SelectTopValue");

      //F: Drop and create the view
      var view = $"[{targetSchema}].[{targetObject.TargetName}]";
      templateContext.Output.WriteLine($"-- StageSourceView: {targetObject.Name}");
      templateContext.Output.WriteLine($"IF OBJECT_ID(N'{view}', N'V') IS NOT NULL");
      templateContext.Output.WriteLine($"    DROP VIEW {view}");
      templateContext.Output.WriteLine(";");
      templateContext.Output.WriteLine("GO");
      templateContext.Output.WriteLine("");
      templateContext.Output.WriteLine($"CREATE VIEW {view}");
      templateContext.Output.WriteLine("AS");

      //G: SELECT TOP when SelectTopValue has a value
      if (!string.IsNullOrWhiteSpace(selectTopValue))
      {
        templateContext.Output.WriteLine($"SELECT TOP {selectTopValue}");
      }
      else
      {
        templateContext.Output.WriteLine("SELECT");
      }

      //H: Default Terms of the Stage source view
      templateContext.Output.WriteLine("     CAST(NULL AS DATETIMEOFFSET) AS [BG_LoadTimestamp]");
      templateContext.Output.WriteLine("    ,CAST(NULL AS NVARCHAR(255)) COLLATE DATABASE_DEFAULT AS [BG_SourceSystem]");

      //I: All other terms
      foreach (var term in targetObject.Terms)
      {
        if (!term.IsDefaultTerm)
        {
          templateContext.Output.WriteLine($"    ,[{alias}].[{term.Name}] AS [{term.Name}]");
        }
      }

      //J: Source table
      templateContext.Output.WriteLine($"FROM [{sourceServer}].[{sourceDatabase}].[{sourceSchema}].[{source}] AS [{alias}]");
      templateContext.Output.WriteLine(";");
      templateContext.Output.WriteLine("GO");
    }
  }
}
```

The parts of the code:

- A and B: the placeholders of the source system and of the Stage layer schema. The generator writes them into the view as text, and Replace Placeholders replaces them later.
- C: the alias and the ID of the source model object of the dataflow set.
- D: the name of the source model object, found by its ID in the architecture model.
- E: the value of `SelectTopValue` of the Stage.
- F: the statements that drop and create the view, with the name the generator gives the Stage source view.
- G: `SELECT TOP` with the value, or `SELECT` when the value is empty.
- H: the Default Terms `BG_LoadTimestamp` and `BG_SourceSystem`, as the generated view writes them.
- I: every term of the Stage that is not a Default Term, read from the source alias.
- J: the source table, named after the source model object, as in the generated view.

#### Limits of the code

The code builds the view from the Stage terms and one source table, not from the dataflow. Compared with the generated view, it does not keep:

- Mappings of terms whose name differs from the source column, and mappings with an expression: part I reads a source column with the name of the term.
- Default Terms other than `BG_LoadTimestamp` and `BG_SourceSystem`, such as those of an incremental load.
- The filter of the incremental load, the filters of the dataflow sets, joins and further dataflow sets.
- `COLLATE DATABASE_DEFAULT` on string columns.

One template module serves only the Stages of one source system, because part A holds the placeholders of that source system.

`SELECT TOP` without `ORDER BY` returns any rows of the source, not the first ones. Each Stage takes its sample on its own, so the samples of related Stages do not match: a Link or Fact can get keys without a matching Hub or Entity row. A sample that changes between loads also brings other keys at each load, and delete detection in a later model object marks the keys that left the sample as deleted.

### Example

The Stage `customer` reads the source table `CUSTOMER`. Without the template module, Show as Code shows this Stage source view:

```
-- StageSourceView: customer_Stage Source View_1
IF OBJECT_ID(N'[{dimensional.mssql#stage#schema_name}].[STG_ST_customer_Source]', N'V') IS NOT NULL
    DROP VIEW [{dimensional.mssql#stage#schema_name}].[STG_ST_customer_Source]
;
GO

CREATE VIEW [{dimensional.mssql#stage#schema_name}].[STG_ST_customer_Source]
AS
SELECT
     CAST(NULL AS DATETIMEOFFSET) AS [BG_LoadTimestamp]
    ,CAST(NULL AS NVARCHAR(255)) COLLATE DATABASE_DEFAULT AS [BG_SourceSystem]
    ,[s1].[CUSTOMER_ID] AS [CUSTOMER_ID]
    ,[s1].[CUSTOMER] COLLATE DATABASE_DEFAULT AS [CUSTOMER]
    ,[s1].[CUSTOMER_TYPE] COLLATE DATABASE_DEFAULT AS [CUSTOMER_TYPE]
    ,[s1].[CUSTOMER_SINCE] AS [CUSTOMER_SINCE]
    ,[s1].[ADDRESS_LINE1] COLLATE DATABASE_DEFAULT AS [ADDRESS_LINE1]
    ,[s1].[ADDRESS_LINE2] COLLATE DATABASE_DEFAULT AS [ADDRESS_LINE2]
    ,[s1].[ADDRESS_LINE3] COLLATE DATABASE_DEFAULT AS [ADDRESS_LINE3]
    ,[s1].[ZIP_CODE] COLLATE DATABASE_DEFAULT AS [ZIP_CODE]
    ,[s1].[COUNTRY] COLLATE DATABASE_DEFAULT AS [COUNTRY]
    ,[s1].[COUNTRY_ISO_CODE] COLLATE DATABASE_DEFAULT AS [COUNTRY_ISO_CODE]
FROM [{dimensional.mssql#bfmmssql#server_name}].[{dimensional.mssql#bfmmssql#database_name}].[{dimensional.mssql#bfmmssql#schema_name}].[CUSTOMER] AS [s1]
;
GO
```

With the template module and `SelectTopValue` set to `1000`, the view selects 1000 rows:

```
-- StageSourceView: customer_Stage Source View_1
IF OBJECT_ID(N'[{dimensional.mssql#stage#schema_name}].[STG_ST_customer_Source]', N'V') IS NOT NULL
    DROP VIEW [{dimensional.mssql#stage#schema_name}].[STG_ST_customer_Source]
;
GO

CREATE VIEW [{dimensional.mssql#stage#schema_name}].[STG_ST_customer_Source]
AS
SELECT TOP 1000
     CAST(NULL AS DATETIMEOFFSET) AS [BG_LoadTimestamp]
    ,CAST(NULL AS NVARCHAR(255)) COLLATE DATABASE_DEFAULT AS [BG_SourceSystem]
    ,[s1].[CUSTOMER_ID] AS [CUSTOMER_ID]
    ,[s1].[CUSTOMER] AS [CUSTOMER]
    ,[s1].[CUSTOMER_TYPE] AS [CUSTOMER_TYPE]
    ,[s1].[CUSTOMER_SINCE] AS [CUSTOMER_SINCE]
    ,[s1].[ADDRESS_LINE1] AS [ADDRESS_LINE1]
    ,[s1].[ADDRESS_LINE2] AS [ADDRESS_LINE2]
    ,[s1].[ADDRESS_LINE3] AS [ADDRESS_LINE3]
    ,[s1].[ZIP_CODE] AS [ZIP_CODE]
    ,[s1].[COUNTRY] AS [COUNTRY]
    ,[s1].[COUNTRY_ISO_CODE] AS [COUNTRY_ISO_CODE]
FROM [{dimensional.mssql#bfmmssql#server_name}].[{dimensional.mssql#bfmmssql#database_name}].[{dimensional.mssql#bfmmssql#schema_name}].[CUSTOMER] AS [s1]
;
GO
```

The template writes the string columns without `COLLATE DATABASE_DEFAULT`. Add it in part I if your source uses another collation than the Stage database.

### Check the result

Open **Manage Term Mappings** of the Stage and choose **Show as Code**. The StageSourceView part starts with `SELECT TOP` and your value. The Stage loader inserts the rows of this view, so after each load the Stage table holds at most that number of rows.

### Failure symptoms and recovery

#### The view still selects all rows

Cause: **SelectTopValue** of the Stage is empty, or the template module does not apply to the Stage. A Stage that existed before the template module gets it only when you select it in the list.  
Fix: set the value, and select the Stage in the template module.

#### Placeholders remain in the deployed view

Cause: parts A and B carry the placeholders of another project, so Replace Placeholders finds no value for them.  
Fix: copy the placeholders from Show as Code of your project, as in step 1 of Create the template module.

#### A test or production load reads only part of the data

Cause: the branch you generate from still holds the template module or sets **SelectTopValue**, for example after a merge of the development branch.  
Fix: delete the template module and clear **SelectTopValue**, then check **Show as Code** as described in the warning under Prerequisites, before you generate for test or production. With the template module and an empty value, the view reads all rows but keeps the limits of the code.

### Related articles

- Reference: [Create a Custom Property](https://knowledge.bigenius-x.com/create-a-custom-property?hsLang=en), [Create a Template Module](https://knowledge.bigenius-x.com/create-a-template-module?hsLang=en), [Understand the Advanced Settings overview](https://knowledge.bigenius-x.com/understand-the-advanced-settings-overview?hsLang=en)
- See also: [Preview a Template Module](https://knowledge.bigenius-x.com/preview-a-template-module?hsLang=en), [Delete a Template Module](https://knowledge.bigenius-x.com/delete-a-template-module?hsLang=en), [Edit a Model Object](https://knowledge.bigenius-x.com/edit-a-model-object?hsLang=en)

- [Getting started](https://knowledge.bigenius-x.com/getting-started?hsLang=en#main-content)

    - [Guidelines](https://knowledge.bigenius-x.com/getting-started?hsLang=en#guidelines)
    - [Start working](https://knowledge.bigenius-x.com/getting-started?hsLang=en#start-working)
    - [Account](https://knowledge.bigenius-x.com/getting-started?hsLang=en#account)
- [General overview](https://knowledge.bigenius-x.com/general-overview?hsLang=en)
- [Artificial Intelligence](https://knowledge.bigenius-x.com/artificial-intelligence?hsLang=en#main-content)

    - [MCP server](https://knowledge.bigenius-x.com/artificial-intelligence?hsLang=en#mcp-server)
- [Application Modules](https://knowledge.bigenius-x.com/application-modules?hsLang=en#main-content)

    - [Administration](https://knowledge.bigenius-x.com/application-modules?hsLang=en#administration)
    - [Solutions](https://knowledge.bigenius-x.com/application-modules?hsLang=en#solutions)
    - [Global Features](https://knowledge.bigenius-x.com/application-modules?hsLang=en#global-features)
    - [Projects](https://knowledge.bigenius-x.com/application-modules?hsLang=en#projects)
    - [Branches](https://knowledge.bigenius-x.com/application-modules?hsLang=en#branches)
    - [Data Connections](https://knowledge.bigenius-x.com/application-modules?hsLang=en#data-connections)
    - [Dataflow Modeling - Overview](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-overview)
    - [Dataflow Modeling - Wizard Steps](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-wizard-steps)
    - [Dataflow Modeling - Terms](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-terms)
    - [Dataflow Modeling - Term Mapping](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-term-mapping)
    - [Dataflow Modeling - Relationships](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-relationships)
    - [Dataflow Modeling - Data Quality](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-data-quality)
    - [Dataflow Modeling - Indexes](https://knowledge.bigenius-x.com/application-modules?hsLang=en#dataflow-modeling-indexes)
    - [Relationship Modeling](https://knowledge.bigenius-x.com/application-modules?hsLang=en#relationship-modeling)
    - [Generate Artifacts](https://knowledge.bigenius-x.com/application-modules?hsLang=en#generate-artifacts)
    - [Project Settings](https://knowledge.bigenius-x.com/application-modules?hsLang=en#project-settings)
    - [Data Marketplace](https://knowledge.bigenius-x.com/application-modules?hsLang=en#data-marketplace)
- [Generators](https://knowledge.bigenius-x.com/generators?hsLang=en#main-content)

    - [Databricks](https://knowledge.bigenius-x.com/generators?hsLang=en#databricks)
    - [Databricks dbt](https://knowledge.bigenius-x.com/generators?hsLang=en#databricks-dbt)
    - [Fabric Lakehouse](https://knowledge.bigenius-x.com/generators?hsLang=en#fabric-lakehouse)
    - [Fabric Warehouse](https://knowledge.bigenius-x.com/generators?hsLang=en#fabric-warehouse)
    - [Microsoft SQL Server](https://knowledge.bigenius-x.com/generators?hsLang=en#microsoft-sql-server)
    - [Oracle](https://knowledge.bigenius-x.com/generators?hsLang=en#oracle)
    - [Snowflake](https://knowledge.bigenius-x.com/generators?hsLang=en#snowflake)
    - [Snowflake dbt](https://knowledge.bigenius-x.com/generators?hsLang=en#snowflake-dbt)
    - [Artifacts](https://knowledge.bigenius-x.com/generators?hsLang=en#artifacts)
    - [Replace Placeholders](https://knowledge.bigenius-x.com/generators?hsLang=en#replace-placeholders)
    - [Target solution environment](https://knowledge.bigenius-x.com/generators?hsLang=en#target-solution-environment)
    - [Deployment](https://knowledge.bigenius-x.com/generators?hsLang=en#deployment)
    - [Deployment with an Azure DevOps pipeline](https://knowledge.bigenius-x.com/generators?hsLang=en#deployment-with-an-azure-devops-pipeline)
    - [Delta Deployment](https://knowledge.bigenius-x.com/generators?hsLang=en#delta-deployment)
    - [Load control environment](https://knowledge.bigenius-x.com/generators?hsLang=en#load-control-environment)
    - [Load data with a native load control](https://knowledge.bigenius-x.com/generators?hsLang=en#load-data-with-a-native-load-control)
    - [Load data with Apache Airflow](https://knowledge.bigenius-x.com/generators?hsLang=en#load-data-with-apache-airflow)
    - [Model Object Type](https://knowledge.bigenius-x.com/generators?hsLang=en#model-object-type)
    - [Properties](https://knowledge.bigenius-x.com/generators?hsLang=en#properties)
    - [Default Terms](https://knowledge.bigenius-x.com/generators?hsLang=en#default-terms)
- [Discovery application](https://knowledge.bigenius-x.com/discovery-application?hsLang=en#main-content)

    - [Discovery configurations](https://knowledge.bigenius-x.com/discovery-application?hsLang=en#discovery-configurations)
- [Best practices](https://knowledge.bigenius-x.com/best-practices?hsLang=en#main-content)

    - [Modeling Approaches](https://knowledge.bigenius-x.com/best-practices?hsLang=en#modeling-approaches)
    - [Use Cases](https://knowledge.bigenius-x.com/best-practices?hsLang=en#use-cases)
    - [Business Rules](https://knowledge.bigenius-x.com/best-practices?hsLang=en#business-rules)
    - [Data Quality Rules](https://knowledge.bigenius-x.com/best-practices?hsLang=en#data-quality-rules)
- [FAQs](https://knowledge.bigenius-x.com/faqs?hsLang=en)
- [Product Release Notes](https://knowledge.bigenius-x.com/product-release-notes?hsLang=en#main-content)

    - [SaaS Application](https://knowledge.bigenius-x.com/product-release-notes?hsLang=en#saas-application)
    - [Discovery application](https://knowledge.bigenius-x.com/product-release-notes?hsLang=en#discovery-application)
    - [Generators](https://knowledge.bigenius-x.com/product-release-notes?hsLang=en#generators)
    - [MCP server](https://knowledge.bigenius-x.com/product-release-notes?hsLang=en#mcp-server)
- [Legal Documents](https://knowledge.bigenius-x.com/legal-documents?hsLang=en#main-content)

    - [Current legal docs](https://knowledge.bigenius-x.com/legal-documents?hsLang=en#current-legal-docs)
    - [Software Product and Limits](https://knowledge.bigenius-x.com/legal-documents?hsLang=en#software-product-and-limits)

- [Contact us](https://knowledge.bigenius-x.com/kb-tickets/new?hsLang=en)
- [Customer Portal](https://knowledge.bigenius-x.com/customer-portal)
- [Sign in](https://knowledge.bigenius-x.com/_hcms/mem/login)

[![biGENIUS logo](https://knowledge.bigenius-x.com/hubfs/TRI_Logo_biGENIUS_2020_RGB-1.svg "biGENIUS logo")](https://www.bigenius-x.com)

<https://www.linkedin.com/company/bigenius> <https://www.youtube.com/@biGENIUS_DWA>

All rights reserved © 2025, biGENIUS AG