A comprehensive .NET sample application demonstrating Microsoft Fabric's Open Mirroring feature. This application showcases how to mirror data from a local SQL database to Microsoft Fabric OneLake using incremental Parquet file uploads.
Microsoft Fabric Open Mirroring allows you to synchronize data from external systems to Fabric OneLake in real-time or near real-time. Unlike traditional ETL processes, Open Mirroring enables:
- Incremental data sync: Only changed/new records are transferred
- Real-time analytics: Data becomes available in Fabric immediately after upload
- Cost-effective: Reduces data transfer costs by syncing only deltas
- Flexible formats: Supports Parquet and other formats optimized for analytics
This sample application consists of:
OrderManagementApp/
βββ Models/
β βββ Order.cs # Order entity with change tracking
β βββ MirroringState.cs # Tracks mirroring state and metadata
βββ Services/
β βββ OrderService.cs # Business logic for order management
β βββ MirroringService.cs # Handles data mirroring to OneLake
β βββ OrderDbContext.cs # Entity Framework database context
βββ Views/ # Terminal.Gui-based user interface
βββ Program.cs # CLI commands and application entry point
- Local SQLite Database: Stores orders with change tracking
- CLI Interface: Command-line tools for bulk operations and mirroring
- GUI Interface: Terminal-based user interface for order management
- Incremental Sync: Tracks and syncs only modified records
- Parquet Export: Generates optimized Parquet files for analytics
- OneLake Integration: Direct upload to Fabric OneLake landing zones
- .NET 9 SDK (Download here)
- Microsoft Fabric tenant with:
- A workspace attached to a Fabric capacity (F, P, or trial)
- A mirrored database configured in your workspace
- Access permissions to the target workspace and mirrored database
-
Clone the repository:
git clone https://github.com/cmaneu/fabric-open-mirroring-sample.git cd fabric-open-mirroring-sample -
Build the application:
dotnet build
-
Run the application:
dotnet run
The application provides several CLI commands:
# Create 10 sample orders (default)
dotnet run create-bulk-orders
# Create custom number of orders
dotnet run create-bulk-orders --count 1000dotnet run setup-mirroring \
--source-table Orders \
--destination-table Orders \
--landing-zone-url "https://onelake.dfs.fabric.microsoft.com/{workspaceId}/{mirroredDbId}/Files/LandingZone" \
--bearer-token "YOUR_BASE64_TOKEN"Parameters:
--source-table: Source table name in local database--destination-table: Target table name in Fabric--landing-zone-url: OneLake landing zone URL for your mirrored database--bearer-token: Base64-encoded authentication token (see authentication section)
# Mirror all changed data since last sync
dotnet run mirror# View and manage orders in terminal UI
dotnet run view-orders
# Or launch main application window
dotnet run# 1. Initialize database with sample data
dotnet run create-bulk-orders --count 100
# 2. Configure mirroring (replace with your values)
dotnet run setup-mirroring \
--source-table Orders \
--destination-table Orders \
--landing-zone-url "https://onelake.dfs.fabric.microsoft.com/{workspaceId}/{mirroredDbId}/Files/LandingZone" \
--bearer-token "YOUR_TOKEN_HERE"
# 3. Perform initial data sync
dotnet run mirror
# 4. Create additional data and sync again
dotnet run create-bulk-orders --count 500
dotnet run mirror
# 5. Launch GUI to view/edit orders
dotnet run view-orders
β οΈ Warning: This method is for demo purposes only! Tokens are valid for approximately 1 hour.
-
Open a Fabric notebook in your workspace with access to the mirrored database
-
Execute this Python code in a notebook cell:
from notebookutils import mssparkutils import base64 # Get token for Azure Storage (OneLake) token = mssparkutils.credentials.getToken('https://storage.azure.com/.default') # Encode token in base64 format encoded = base64.b64encode(token.encode()) print(encoded)
-
Copy the token (without the
b'prefix and'suffix) -
Use the token in the
setup-mirroringcommand
For production scenarios, consider:
- Service Principal authentication with proper credentials management
- Managed Identity when running in Azure
- Key Vault integration for secure token storage
The mirroring process creates:
data/
βββ parquet/
βββ orders/
βββ _metadata.json # Table schema and key columns
βββ 00000000000000000001.parquet # Initial data batch
βββ 00000000000000000002.parquet # Incremental batch 1
βββ 00000000000000000003.parquet # Incremental batch 2
| Column | Type | Description |
|---|---|---|
__rowMarker__ |
int | Row operation marker (0=insert/update, 2=delete) |
OrderId |
int | Primary key |
OrderNumber |
string | Unique order identifier |
CustomerName |
string | Customer full name |
OrderDate |
datetime | When order was placed |
TotalAmount |
decimal | Order total amount |
LastUpdatedAt |
datetime | Last modification timestamp |
{
"keyColumns": ["OrderId"]
}- SQLite database stored in
data/orders.db - Automatic schema creation on first run
- Soft delete support with
IsDeletedflag - Change tracking via
LastUpdatedAttimestamp
The application tracks mirroring state in the States table:
- Last mirrored timestamp: Ensures incremental sync
- File numbering: Maintains sequential Parquet file naming
- OneLake credentials: Securely stores connection information
"Authentication failed"
- Verify your bearer token is valid and not expired
- Ensure you have proper permissions to the workspace and mirrored database
- Check that the OneLake URL format is correct
"No data to mirror"
- Verify orders exist in the local database:
dotnet run view-orders - Check if mirroring was already performed (only changed data is synced)
- Create new orders:
dotnet run create-bulk-orders
"Parquet file creation failed"
- Ensure the
data/parquet/ordersdirectory is writable - Check available disk space
- Verify .NET 9 runtime is properly installed
"OneLake upload failed"
- Confirm the landing zone URL format:
https://onelake.dfs.fabric.microsoft.com/{workspaceId}/{mirroredDbId}/Files/LandingZone - Verify workspace ID and mirrored database ID are correct
- Check network connectivity to OneLake
Enable detailed logging by setting environment variable:
$env:DOTNET_ENVIRONMENT="Development"
dotnet run- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Microsoft Fabric Documentation
- OneLake Overview
- Mirroring in Microsoft Fabric
- Parquet Format Specification
For questions and support:
- Create an issue in this repository
- Check the Microsoft Fabric community
- Review the troubleshooting section above