T-SQL 2 C# Migration

LLM-Powered Code Migration at Scale

Pacific Dev Logo

The Challenge

  • ~20 years of business logic grown into > 1500 stored procs
  • High interdependence
  • Difficult to debug and maintain
  • Difficult to test
  • Challenging to integrate into CI/CD pipeline with automated testing

Large Language Models

What They Are

  • Transformer-based neural networks trained on massive text corpora
  • Capable of understanding and generating human-like text
  • Foundation for modern AI assistants and code generation

Evolution of Context Windows

Model Context Window Year
GPT-1 512 tokens 2018
GPT-3 4K tokens 2020
GPT-4 128K tokens 2023
Claude 3 200K tokens 2024
O3 / Claude 4.7 2M+ tokens 2025

Frontier Model Architecture

Not just an LLM - a complex stack of tools

  • Base LLM: Core transformer model
  • Reasoning Engine: Chain-of-thought, planning, multi-step logic
  • Model Router: Directing requests to appropriate specialized models
  • Input/Output Processing: Request handling, response formatting

Our Migration Pipeline

Claude Claude Generate Migration Build Test Generate Tests Build Test Verify test logic Run tests Fix build errors Fix build errors Fix migration

One-Shot Code Migration Prompt

Initial Prompt

"You need to migrate SQL to C# using Entity Framework Core..."

Detailed Setup Explanation

"Stored procs in MS SQL, output in C# in this directory <...>, 
use this namespace <...>, DB Contexts are CrmDbContext,..., 
use DI for dependencies, create Interface as well..."

List of Dependencies

"SP: fma_web_Processors_Tier_Check, Tables:..., EF names:..."

One-Shot Code Migration (cont'd)

Utility Functions Available

public class Functions
{    
    public async Task<int> CustomerHasFlag(string customerID, int categoryId)
    {
        ...

Example Output

public class fma_web_Limits_Check : Ifma_web_Limits_Check
{
    private readonly CrmDbContext _crmDbContext;
    ...

Further Instructions & Tweaks

Highest priority is perfect match of logic flow. 
Be aware of different null handling...

Full Migration Prompt

Loading prompt content...

One-Shot Test Generation

SQL Logic

IF @CustomerID IN ('511555') --AND @SiteID = 1
BEGIN
    SET @returnProcessorCode = 'Compsta3D'
    SELECT @returnProcessorCode
    RETURN
END

Generated Test

// Special customer 511555 (should return Compsta3D)
testParams.Add(new TestParamsAndResult()
{
    ParameterValues = new List<object>()
    {
        "511555", // CustomerID
        "visa",   // CardType
        100.00m,  // Amount
        1,        // SiteID
        "I",      // LocationCode
        CreditCardNumberGenerator.GetNumberByType("visa", random) // CreditCardNo
    }
});

Focus: Hit all code paths without superfluous test cases

Migration UI

Browser-based dashboard

  • Progress tracking of migration status
  • Historical tracking of Pass/Fail
  • Manual triggering of individual steps in the pipeline

Common Migration Issues

  • LEFT JOIN vs .Join(): Different null handling semantics
  • Casing: IsIBO vs. IsIbo inconsistencies
  • Ambiguous References: TransactionStatusCode without alias
  • DateTime.Now: Time zone and testability issues

✨ Core logic is understood and translated well!

One-Shot vs. Agentic Approaches

One-Shot

  • Single prompt, complete context
  • Faster execution
  • Easier to debug

Agentic

  • Multi-step reasoning
  • Can self-correct
  • Can act on it's own (in limits)

Automating with Claude Code

The Feedback Pipeline

  • Each pipeline step callable from outside
  • Investigative tools for debugging
  • Hands-off execution
  • Human-in-the-loop only at the end

Claude Code Functions

Via dotnet run command line

  • RunMigration(...)
  • GenerateTests(...)
  • RunTests(...)
  • GetNextSPForConversion(...)
  • GetDependencyXYZ(...)
  • But also system:
  • DIR, find, create files, git, dotnet build/run...
Claude Generate Build Gen Tests Build Tests Verify Fix Fix Fix migration

Learnings, Tips & Tricks

  • Things are moving fast!
  • Massive Context: Unlike 2024, use it all!
  • Be Concise: Understand deeply, constrain tightly
  • Fall Forward: Design prompts for success paths
  • Classic Techniques Still Work:
    • Roleplaying: "You are a world-class engineer...", encouragement, bribery
  • Read the Guides: OpenAI, Anthropic, Google prompt guides remain valuable

Resources & Further Reading

GitHub QR Code

GitHub Repository QR Code

Scan for GitHub repo

Questions?

Thank you!