9.3 KiB
Migration Guide: Core20 ORM to EF Core 8.0
Overview
This document outlines the process of migrating from the Core20 ORM system to Entity Framework Core 8.0, using the BudgetConfigDefaultSetting implementation as a reference example.
Database Connection Management Comparison
Core20 Approach
// Core20 uses static SQL context and connection strings
static string SQL_QUERY_FROM = @"[fp].[BudgetConfigDefaultSetting] OBJ";
internal const string UPDATE_TABLE_NAME = "fp.BudgetConfigDefaultSetting";
- Uses static SQL contexts
- Manages connections through
SqlContext.Current - Relies on connection string keys
- Manual SQL query construction
- Schema is defined in SQL queries
EF Core Approach
public class OnePlanDbContext : DbContext
{
public DbSet<BudgetConfigDefaultSetting> BudgetConfigDefaultSettings { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BudgetConfigDefaultSetting>(entity =>
{
entity.ToTable("BudgetConfigDefaultSetting", "fp");
// ... other configurations
});
}
}
- Connection management through DbContext
- Dependency injection for context lifecycle
- Fluent API for schema definition
- Type-safe queries
- Connection string in configuration
ORM Feature Comparison
| Feature | Core20 | EF Core | Migration Effort |
|---|---|---|---|
| Schema Definition | SQL Strings | Fluent API/Attributes | Medium |
| Query Building | String Concatenation | LINQ | High |
| Change Tracking | Manual (IsDirty) | Automatic | Low |
| Transactions | Manual | Built-in | Medium |
| Relationships | Manual Loading | Navigation Properties | High |
| Validation | Custom Implementation | Data Annotations/Custom | Medium |
| Bulk Operations | Custom SQL | Extensions Available | Medium |
| Security | Manual SQL Filters | Global Query Filters | Medium |
Migration Steps
-
Entity Class Migration
// From Core20: [Serializable] public partial class BudgetConfigDefaultSetting : ReadWriteBase<BudgetConfigDefaultSetting> // To EF Core: public class BudgetConfigDefaultSetting { public int SettingId { get; set; } public string Name { get; set; } public string Description { get; set; } public bool DefaultValue { get; set; } public DateOnly DateCreated { get; set; } } -
Configuration Migration
public class BudgetConfigDefaultSettingConfiguration : IEntityTypeConfiguration<BudgetConfigDefaultSetting> { public void Configure(EntityTypeBuilder<BudgetConfigDefaultSetting> builder) { builder.ToTable("BudgetConfigDefaultSetting", "fp"); builder.HasKey(e => e.SettingId); builder.Property(e => e.Name).IsRequired(); // ... other configurations } } -
Repository Pattern Implementation
- Replace static loading methods with repository methods
- Convert SQL queries to LINQ expressions
- Implement unit of work pattern if needed
Code Examples Comparison
Loading Records
// Core20
var records = BudgetConfigDefaultSetting.LoadByColumn("Name", "SomeName");
// EF Core
var records = await _repository.GetByNameAsync("SomeName");
Saving Changes
// Core20
setting.MarkDirty();
setting.Save();
// EF Core
await _repository.UpdateAsync(setting);
Relationships
// Core20
var linkedSettings = BudgetConfigDefaultSetting.LoadByLinks("LinkTable", "ColumnName", ids);
// EF Core
var linkedSettings = await _repository.GetByLinksAsync(
_context.Links.Where(l => ids.Contains(l.Id)),
link => link.SettingId
);
Migration Effort Assessment
High Effort Areas
-
Query Conversion
- Converting raw SQL to LINQ expressions
- Implementing type-safe joins
- Replacing string-based queries
-
Relationship Management
- Defining navigation properties
- Converting manual loading to eager/lazy loading
- Implementing proper relationship configurations
-
Transaction Management
- Replacing manual transaction handling
- Implementing unit of work pattern
- Managing context lifecycle
Medium Effort Areas
-
Schema Configuration
- Converting SQL schema to Fluent API
- Setting up entity configurations
- Defining indexes and constraints
-
Validation Logic
- Implementing validation attributes
- Converting custom validation rules
- Setting up FluentValidation if needed
Low Effort Areas
- Basic CRUD Operations
- Converting simple load/save operations
- Implementing basic repository methods
- Setting up entity properties
Best Practices for Migration
-
Incremental Migration
- Migrate one entity at a time
- Keep both systems running during migration
- Implement facade pattern for transition
-
Testing Strategy
- Create integration tests first
- Verify queries produce same results
- Test performance impact
-
Performance Considerations
- Use compiled queries for frequent operations
- Implement proper indexing
- Monitor query performance
-
Security Migration
- Replace manual SQL filters with Global Query Filters
- Implement proper user context
- Audit sensitive operations
Tools and Utilities
-
Essential Tools
- EF Core Power Tools
- SQL Server Profiler
- dotnet ef CLI tools
-
Recommended Extensions
- EF Core Bulk Extensions
- AutoMapper
- FluentValidation
AI Assistance for Migration
Using AI Tools for Migration Support
The migration process can be significantly accelerated using Claude and WindSurf. Here's how to effectively leverage these tools:
Using Claude for Architecture and Analysis
Claude excels at high-level analysis and providing detailed implementation guidance. Here are effective prompting strategies:
Example 1: Initial Analysis Prompt
I need to migrate a Core20 ORM implementation to EF Core 8.0. Here are my source files:
[Paste your Core20 files]
Please:
1. Analyze the current implementation
2. Identify key patterns and functionality
3. Propose an EF Core equivalent structure
4. Provide a sample implementation for one entity
5. List potential challenges and their solutions
Example 2: Detailed Implementation Prompt
Please help me implement the EF Core repository for this entity:
[Paste your entity class]
Requirements:
1. Maintain existing functionality
2. Use async/await pattern
3. Implement proper dependency injection
4. Include repository interface
5. Show example service layer integration
Using WindSurf for Code Generation
WindSurf is particularly effective for handling specific code generation tasks. Here's how to use it effectively:
-
Repository Migration
// WindSurf prompt: // Generate EF Core repository for this Core20 entity: // [Insert entity details] -
Entity Configuration
// WindSurf prompt: // Create EF Core entity configuration class for: // [Insert schema details]
Best Practices for AI-Assisted Migration
-
Preparation
- Document all existing functionality
- Identify critical patterns
- Create test cases before migration
-
Prompting Strategy
- Use Claude for:
- Architecture decisions
- Pattern analysis
- Complex transformations
- Documentation generation
- Use WindSurf for:
- Code generation
- Schema translations
- LINQ query conversions
- Repetitive transformations
- Use Claude for:
-
Validation Process
- Review AI-generated code thoroughly
- Test against existing functionality
- Verify performance characteristics
- Check security implications
AI Tools Comparison for Migration Tasks
| Task | Claude | WindSurf | Best Practice |
|---|---|---|---|
| Architecture Analysis | Excellent | Limited | Use Claude |
| Code Generation | Good | Excellent | Use WindSurf with Claude's guidance |
| Pattern Recognition | Excellent | Good | Start with Claude, implement with WindSurf |
| Documentation | Excellent | Limited | Use Claude |
| Edge Cases | Good | Good | Use both tools complementarily |
Tool-Specific Best Practices
Claude
- Provide complete context
- Ask for step-by-step explanations
- Request multiple approaches
- Use for architectural decisions
WindSurf
- Focus on specific code generation tasks
- Use for repetitive transformations
- Leverage for LINQ query conversions
- Apply to schema migrations
Recommended Workflow
-
Analysis Phase (Claude)
- System architecture review
- Pattern identification
- Migration strategy development
-
Implementation Phase (WindSurf)
- Code generation
- Entity configurations
- Repository implementations
-
Validation Phase (Both)
- Code review
- Test case execution
- Performance validation
Conclusion
The migration from Core20 to EF Core represents a significant modernization effort that will result in more maintainable, type-safe, and performant code. By leveraging Claude for strategic planning and WindSurf for implementation, teams can significantly accelerate the migration process while maintaining high quality standards. The key is to use each tool's strengths appropriately and maintain a consistent validation process throughout the migration.