PluginBench
Skill
Official
Review
Audit score 70

ef-core

github/awesome-copilot

Best practices guidance for Entity Framework Core design, querying, and performance.

What is ef-core?

This skill provides expert guidance on Entity Framework Core best practices across data context design, entity modeling, performance optimization, migrations, and security. Use it when building or reviewing EF Core implementations to ensure code follows established patterns and avoids common pitfalls.

  • Reviews DbContext design for cohesion and proper configuration patterns
  • Evaluates entity relationships, constraints, and navigational properties
  • Identifies performance issues like N+1 queries and suggests optimization techniques
  • Guides migration strategy and naming conventions
  • Recommends secure querying practices and SQL injection prevention
  • Advises on change tracking, transactions, and concurrency control

How to install ef-core

npx skills add https://github.com/github/awesome-copilot --skill ef-core
Claude Code
Cursor
Windsurf
Cline

How to use ef-core

  1. 1.Ask the skill to review your EF Core code or DbContext design
  2. 2.Describe the specific area you need guidance on (querying, migrations, performance, etc.)
  3. 3.Provide relevant code snippets or describe your current implementation
  4. 4.Receive best practice recommendations aligned with the skill's guidance
  5. 5.Apply suggested improvements to your codebase

Use cases

Good for
  • Code review of EF Core data access layers to identify anti-patterns
  • Designing DbContext and entity structures for new features
  • Optimizing slow queries using Include(), AsNoTracking(), and projections
  • Planning migration strategy for production database changes
  • Implementing testing strategies with in-memory and SQLite providers
Who it's for
  • Backend developers using Entity Framework Core
  • Database architects designing data models
  • DevOps engineers managing migrations and deployments
  • QA engineers testing data access layers
  • Teams building .NET applications with EF Core

ef-core FAQ

When should I use AsNoTracking() in my queries?

Use AsNoTracking() for read-only queries where you don't need to track changes. This reduces memory overhead and improves performance for queries that only retrieve data without modifications.

How do I avoid N+1 query problems?

Use Include() to eager load related entities in a single query, or use Select() projections to retrieve only the data you need. Understand when your LINQ queries execute to avoid multiple database round trips.

What's the difference between data annotations and fluent API configuration?

Both configure entity constraints and relationships, but fluent API in OnModelCreating is more powerful and keeps entity classes cleaner. Use fluent API for complex configurations and separate them using IEntityTypeConfiguration.

Should I use raw SQL queries in EF Core?

Prefer strongly-typed LINQ queries for safety and maintainability. If you must use raw SQL, always use parameterized queries to prevent SQL injection. Consider database functions for complex operations instead.

What DbContext lifetime should I use in a web application?

Use scoped DbContext lifetime in web applications (one instance per request). This ensures proper resource cleanup and avoids issues with concurrent requests sharing the same context.

Full instructions (SKILL.md)

Source of truth, from github/awesome-copilot.


name: ef-core description: 'Get best practices for Entity Framework Core'

Entity Framework Core Best Practices

Your goal is to help me follow best practices when working with Entity Framework Core.

Data Context Design

  • Keep DbContext classes focused and cohesive
  • Use constructor injection for configuration options
  • Override OnModelCreating for fluent API configuration
  • Separate entity configurations using IEntityTypeConfiguration
  • Consider using DbContextFactory pattern for console apps or tests

Entity Design

  • Use meaningful primary keys (consider natural vs surrogate keys)
  • Implement proper relationships (one-to-one, one-to-many, many-to-many)
  • Use data annotations or fluent API for constraints and validations
  • Implement appropriate navigational properties
  • Consider using owned entity types for value objects

Performance

  • Use AsNoTracking() for read-only queries
  • Implement pagination for large result sets with Skip() and Take()
  • Use Include() to eager load related entities when needed
  • Consider projection (Select) to retrieve only required fields
  • Use compiled queries for frequently executed queries
  • Avoid N+1 query problems by properly including related data

Migrations

  • Create small, focused migrations
  • Name migrations descriptively
  • Verify migration SQL scripts before applying to production
  • Consider using migration bundles for deployment
  • Add data seeding through migrations when appropriate

Querying

  • Use IQueryable judiciously and understand when queries execute
  • Prefer strongly-typed LINQ queries over raw SQL
  • Use appropriate query operators (Where, OrderBy, GroupBy)
  • Consider database functions for complex operations
  • Implement specifications pattern for reusable queries

Change Tracking & Saving

  • Use appropriate change tracking strategies
  • Batch your SaveChanges() calls
  • Implement concurrency control for multi-user scenarios
  • Consider using transactions for multiple operations
  • Use appropriate DbContext lifetimes (scoped for web apps)

Security

  • Avoid SQL injection by using parameterized queries
  • Implement appropriate data access permissions
  • Be careful with raw SQL queries
  • Consider data encryption for sensitive information
  • Use migrations to manage database user permissions

Testing

  • Use in-memory database provider for unit tests
  • Create separate testing contexts with SQLite for integration tests
  • Mock DbContext and DbSet for pure unit tests
  • Test migrations in isolated environments
  • Consider snapshot testing for model changes

When reviewing my EF Core code, identify issues and suggest improvements that follow these best practices.