Overview
This guide will help you successfully migrate your Ditto C# application from the legacy query builder APIs to the modern DQL (Ditto Query Language). After reviewing this documentation, you’ll understand how to convert method chaining patterns to DQL syntax and systematically update your data operations.AI Agent Prompt
Use this prompt when working with an AI coding assistant to migrate your Ditto C# app from legacy query builder to DQL.Copy AI Migration Prompt (Click to Expand)
Copy AI Migration Prompt (Click to Expand)
Syntax Change Reference
Document Query Syntax
Document Query AllQuery Response Handling
Legacy Query Builder → DQL ResponseObserver Migration
Legacy Query Builder → DQL Store Observer MigrationSync Subscriptions Migration
Legacy Query Builder → DQL Sync Subscriptions Subscribe with QueryCounter Type Migration
PN_COUNTER is the DQL equivalent of the legacy
DittoCounter type. When migrating counter operations from the legacy query builder’s counter methods, use PN_INCREMENT BY in the APPLY clause. This maintains full compatibility with existing counter data created by DittoCounter.Attachment Operations with DQL
Attachment Creation and StoragePerformance Enhancements
Indexes for Improved Query Performance
DQL observers and queries benefit significantly from proper indexing. When migrating from the legacy query builder to DQL, creating indexes on frequently queried fields is essential for maintaining optimal performance. Why Indexes Matter for DQL:- DQL observers support advanced features like aggregates and projections
- These advanced features require full database scans to ensure consistent results
- Indexes dramatically reduce query execution time by avoiding full scans
- Combining indexes with observers provides better performance than legacy query builder
- Create indexes on fields used in
WHEREclauses - Create indexes before registering observers for those queries
- Use compound indexes for queries with multiple filter conditions
- Monitor query performance and add indexes as needed
Common Pitfalls & Solutions
Missing Parameter Binding
Problem: Not properly binding parameters in DQL queries Solution: Always use parameterized queries:Attachment Handling
Problem: Incorrect attachment handling in DQL queries Solution: Use proper ATTACHMENT annotation:Counter Type Migration
Problem: Legacy counter operations not working with DQL Solution: Use PN_INCREMENT function for counter operations:QueryResult Materialization
Problem: HoldingDittoQueryResult and DittoQueryResultItem references beyond their intended scope leads to memory issues because the associated native memory is not freed.
Solution: Make sure you wrap the DittoQueryResult in a using statement, or explicitly Dispose() when done. Use one of the two recommended patterns: