As a .NET developer, you have a secret weapon: ChatGPT and Claude understand C#, ASP.NET, Entity Framework and the .NET ecosystem very well. Here are 20 prompts that I use weekly to save hours.
Code Generation Prompts
1. Entity Framework migration: "Generate an Entity Framework Core migration for a User entity with Name (string), Email (string, unique), CreatedAt (DateTime), and a foreign key to Company. Include proper indexes."
2. Repository pattern: "Create a generic repository pattern in C# with async methods for CRUD operations using Entity Framework Core. Include IRepository interface and implementation."
3. API endpoint: "Write an ASP.NET Core 8 minimal API endpoint for user registration with validation using FluentValidation, password hashing with BCrypt, and JWT token generation."
Debugging Prompts
4. Exception analysis: "I'm getting this exception in my C# code: [paste exception]. Here's the relevant code: [paste code]. What's causing this and how do I fix it?"
5. Performance issue: "This EF Core query is slow: [paste LINQ query]. How do I optimize it? Should I use raw SQL, AsNoTracking, or split the query?"
Unit Test Prompts
6. xUnit tests: "Write comprehensive xUnit tests for this C# service: [paste service]. Include happy path, edge cases, and exception scenarios. Use Moq for mocking."
7. Test data builder: "Create a Builder pattern class for generating test data for this entity: [paste entity class]."
Code Review Prompts
8. Full review: "Review this C# code for: SOLID principles violations, potential performance issues, security vulnerabilities, missing null checks, and async/await anti-patterns: [paste code]"
9. Refactor: "Refactor this method to be more readable, follow C# conventions, and reduce cognitive complexity: [paste method]"
Architecture Prompts
10. Design pattern: "I need to implement a notification system that sends email, SMS and push notifications. Show me the best design pattern in C# 12 with dependency injection."
๐ก Pro tip: When using ChatGPT for .NET code, always specify the .NET version (8, 9), mention if you're using Minimal APIs vs Controllers, and paste your relevant entity/DTO classes. Context = better code output.
The 10 More Essential Prompts
- 11. "Convert this EF Core query to use Dapper for better performance"
- 12. "Write middleware for JWT validation in ASP.NET Core 8"
- 13. "Create a health check endpoint for my ASP.NET Core API"
- 14. "Implement Redis caching for this service method"
- 15. "Write a background service using IHostedService for this task"
- 16. "Convert this callback-based code to async/await properly"
- 17. "Review this SQL query for N+1 problems in Entity Framework"
- 18. "Create AutoMapper profiles for these DTOs and entities"
- 19. "Write a Polly retry policy for this HTTP client"
- 20. "Generate Swagger/OpenAPI documentation for this controller"