Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
AI

AI Coding Assistant: ChatGPT Prompts That Generate Production-Ready Code

- 05.02.26 - ErcanOPAK

Tired of AI giving you buggy code snippets? These structured prompts extract perfect, tested code from ChatGPT and Copilot.

The Structure for Perfect Code Generation:

ROLE: Senior [Language] Developer with 10 years experience
TASK: Create [specific feature]
CONSTRAINTS: [technical limitations]
REQUIREMENTS: [must-have features]
OUTPUT FORMAT: [code structure]
TEST: [validation criteria]

Example:
ROLE: Senior C#/.NET Developer with 10 years experience
TASK: Create a repository pattern implementation with Entity Framework Core
CONSTRAINTS: .NET 8, SQL Server, async/await, no stored procedures
REQUIREMENTS: Generic repository, specific repositories, unit of work, DI ready
OUTPUT FORMAT: Complete classes with XML documentation
TEST: Include unit tests using xUnit and Moq

Prompt 1: Complete CRUD API Endpoint

Create a complete ASP.NET Core Web API endpoint for managing products in an e-commerce system.

Requirements:
1. Use .NET 8 minimal APIs
2. Entity Framework Core with SQL Server
3. Repository pattern with generic repository
4. DTOs for request/response (separate from entities)
5. AutoMapper for entity-DTO mapping
6. FluentValidation for request validation
7. Global error handling middleware
8. Swagger/OpenAPI documentation with examples
9. Response caching for GET endpoints
10. Rate limiting on POST/PUT/DELETE

Include:
- Product entity with: Id, Name, Description, Price, StockQuantity, CategoryId, CreatedDate
- ProductDto for requests/responses
- ProductRepository with all CRUD operations
- ProductsController with endpoints:
  GET /api/products (with pagination, sorting, filtering)
  GET /api/products/{id}
  POST /api/products
  PUT /api/products/{id}
  DELETE /api/products/{id}
- Unit tests using xUnit (test repository and controller)
- Integration tests using TestServer

Add XML comments for Swagger with examples.
Include proper HTTP status codes (200, 201, 400, 404, 500).
Add request/response examples in Swagger.

Write complete, production-ready code that I can copy-paste into my project.

Prompt 2: React Component with TypeScript & Tests

Create a complete React TypeScript component for a data table with advanced features.

Requirements:
1. React 18 with TypeScript strict mode
2. Material-UI v5 components
3. React Query for data fetching
4. React Hook Form for inline editing
5. Virtual scrolling for performance (1000+ rows)
6. Column sorting (multi-column)
7. Global filtering and column filtering
8. Row selection with checkboxes
9. Inline row editing with validation
10. Export to CSV/Excel functionality
11. Pagination (client-side and server-side options)
12. Responsive design (mobile-friendly)

Features:
- Lazy loading with infinite scroll option
- Column resizing and reordering
- Row grouping and aggregation
- Custom cell renderers
- Theme support (light/dark mode)
- Accessibility (ARIA labels, keyboard navigation)
- Localization support
- Undo/redo for edits
- Bulk operations

Include:
1. DataTable component with all props typed
2. Custom hooks for data management
3. Context for table state
4. Utility functions for filtering/sorting
5. Complete TypeScript interfaces
6. Unit tests with Jest and React Testing Library
7. Storybook stories for documentation
8. Performance optimizations (React.memo, useCallback)
9. Error boundary for the component
10. Loading and empty states

Write production-ready code with proper error handling, loading states, and comprehensive documentation.
Include examples of how to use the component with mock data.

Prompt 3: Database Migration & Seeding

Create a complete database setup for a SaaS application using Entity Framework Core migrations.

Requirements:
1. .NET 8 with EF Core 8
2. SQL Server database
3. Multi-tenant architecture (database per tenant)
4. Audit logging (who changed what and when)
5. Soft delete implementation
6. Row-level security for multi-tenancy
7. Database indexes for performance
8. Seed data for development
9. Migration scripts for production deployment

Entities needed:
1. Tenant (Id, Name, ConnectionString, IsActive, Created)
2. User (Id, TenantId, Email, HashedPassword, Roles, LastLogin)
3. Product (Id, TenantId, Name, Description, Price, Category)
4. Order (Id, TenantId, UserId, TotalAmount, Status, CreatedDate)
5. OrderItem (Id, OrderId, ProductId, Quantity, Price)
6. AuditLog (Id, TenantId, UserId, Action, TableName, RecordId, OldValues, NewValues, Timestamp)

Requirements for each entity:
- Base entity with common fields (Id, CreatedDate, ModifiedDate, CreatedBy, ModifiedBy)
- Soft delete with IsDeleted and DeletedDate
- Tenant isolation (TenantId foreign key)
- Proper indexes on foreign keys and frequently queried columns
- Composite unique constraints where needed
- Entity configurations in separate configuration classes
- Value objects for complex types (Money, Address, etc.)

Create:
1. Complete entity classes with relationships
2. DbContext with multi-tenant support
3. Entity configurations for each entity
4. Initial migration with seed data
5. Migration for adding new features
6. Script to apply migrations in production
7. Seed data for development (100 products, 50 users, 200 orders)
8. Repository pattern implementation
9. Unit tests for repositories
10. Performance considerations for large datasets

Include:
- Connection resiliency with retry logic
- Database health checks
- Migration rollback procedures
- Data encryption for sensitive fields
- Change tracking for auditing
- Database views for complex queries
- Stored procedures for batch operations

Write complete, production-ready code that follows best practices for security, performance, and maintainability.

Prompt 4: DevOps Pipeline Configuration

Create a complete Azure DevOps pipeline for a .NET microservices application.

Requirements:
1. 5 microservices (API Gateway, User Service, Product Service, Order Service, Payment Service)
2. Each service: ASP.NET Core 8, Docker, SQL Server, Redis cache
3. Infrastructure: Kubernetes (AKS), Azure SQL, Azure Redis, Application Insights
4. Pipeline stages: Build, Test, Scan, Package, Deploy, Monitor

Pipeline should include:
1. Multi-stage YAML pipeline
2. Parallel builds for each microservice
3. Unit tests, integration tests, load tests
4. Security scanning (SAST, SCA, container scanning)
5. Code quality gates (SonarQube analysis)
6. Docker image building and pushing to ACR
7. Kubernetes manifest generation with Helm
8. Blue-green deployment to AKS
9. Database migrations as part of deployment
10. Smoke tests post-deployment
11. Rollback procedures
12. Monitoring and alerting setup

Add:
- Environment-specific configurations (dev, staging, prod)
- Feature flag deployment
- Canary releases configuration
- Automated rollback on failure
- Cost optimization (auto-scaling, resource limits)
- Backup procedures for databases
- Disaster recovery steps
- Compliance checks (GDPR, HIPAA if applicable)

Create complete YAML files for:
1. azure-pipelines.yml (main pipeline)
2. Dockerfile for each microservice
3. Helm charts for each service
4. Kubernetes manifests for all environments
5. Database migration scripts
6. Infrastructure as Code (Terraform/Bicep)
7. Monitoring dashboards (Grafana/Application Insights)
8. Alert rules for critical metrics

Include best practices for:
- Secret management (Azure Key Vault)
- Network security (NSG, private endpoints)
- Performance optimization (caching, CDN)
- High availability (multiple regions)
- Cost management (budget alerts, resource tagging)

Write production-ready configurations that follow Azure Well-Architected Framework principles.

Related posts:

Make Better Decisions Under Uncertainty

AI Prompt — Explain Code Like a Tech Lead

AI Prompt — Refactor Code Without Breaking Behavior

Post Views: 4

Post navigation

Windows 11 Power User Secret: How PowerToys Makes You 3x More Productive
.NET Core Middleware Magic: How to Build Pipeline Filters That Transform Your API

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  
« Jan    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (934)
  • How to add default value for Entity Framework migrations for DateTime and Bool (830)
  • Get the First and Last Word from a String or Sentence in SQL (822)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (708)
  • Add Constraint to SQL Table to ensure email contains @ (571)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (552)
  • Average of all values in a column that are not zero in SQL (517)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (473)
  • Find numbers with more than two decimal places in SQL (436)

Recent Posts

  • C#: Use init Accessor to Create Immutable Objects Without Constructor Boilerplate
  • C#: Use Index and Range Operators for Cleaner Array Slicing
  • C#: Use Null-Coalescing Assignment to Simplify Lazy Initialization
  • SQL: Use CHAR Instead of VARCHAR for Fixed-Length Columns to Save Space
  • SQL: Use CROSS APPLY Instead of Subqueries for Better Performance
  • .NET Core: Use Required Modifier to Force Property Initialization
  • .NET Core: Use Global Using Directives to Avoid Repeating Imports
  • Git: Use git restore to Unstage Files Without Losing Changes
  • Git: Use git bisect to Find Which Commit Introduced a Bug
  • AJAX: Use Fetch with Signal to Cancel Requests When User Navigates Away

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (934)
  • How to add default value for Entity Framework migrations for DateTime and Bool (830)
  • Get the First and Last Word from a String or Sentence in SQL (822)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (708)

Recent Posts

  • C#: Use init Accessor to Create Immutable Objects Without Constructor Boilerplate
  • C#: Use Index and Range Operators for Cleaner Array Slicing
  • C#: Use Null-Coalescing Assignment to Simplify Lazy Initialization
  • SQL: Use CHAR Instead of VARCHAR for Fixed-Length Columns to Save Space
  • SQL: Use CROSS APPLY Instead of Subqueries for Better Performance

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com