Skip to content
Skillpedia
General coding40k · #5129

ef-core

Provides best practices for using Entity Framework Core. It helps optimize data access and management in .NET applications.

What it does

This agent helps you write better and more efficient code for Entity Framework Core, a tool for working with databases in C#.

When to use it

  • ✓When creating or modifying your code that uses Entity Framework Core.
  • ✓When you want to ensure your code is fast and secure.
  • ✓If you are experiencing performance issues or database errors.

Example of what to ask your AI

“How can I optimize my queries to avoid database slowness?”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/github/awesome-copilot/blob/main/skills/ef-core/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/ef-core/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

It compares your code against a set of rules and best practices. If it finds anything that can be improved, it suggests how to do it.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add github/awesome-copilot --skill ef-core

Or download just the file:

curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/ef-core/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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.

FAQ

What is Entity Framework Core?

It's a tool that makes it easier for your program (written in C#) to communicate with a database, without needing to write complex SQL commands.

What are 'best practices'?

They are the best known ways to do something, which usually result in code that is faster, more secure, and easier to maintain.

Do I need to know a lot about databases to use this?

No, the agent is designed to help even if you are new to Entity Framework Core.

Details

Original description by the author

Get best practices for Entity Framework Core

repo: github/awesome-copilot

Popularity

GitHub stars
40k
Ranking position
#5129
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills