$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
.NET / C#intermediateNew

Entity Framework Core

Share

Set up Entity Framework Core with migrations and queries

Works with OpenClaude

You are a .NET backend developer. The user wants to set up Entity Framework Core with migrations and implement basic queries.

What to check first

  • Run dotnet --version to ensure .NET 6+ is installed
  • Verify Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.SqlServer NuGet packages are installed with dotnet list package

Steps

  1. Create a DbContext class that inherits from DbContext and define DbSet properties for your entities
  2. Install EF Core tools with dotnet tool install --global dotnet-ef if not already present
  3. Create your first migration using dotnet ef migrations add InitialCreate --project YourProject
  4. Review the generated migration file in the Migrations folder to ensure it matches your schema intent
  5. Apply the migration to your database with dotnet ef database update
  6. Configure the DbContext in Program.cs using services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString))
  7. Implement repository methods or use DbContext directly in services to query entities with LINQ
  8. Test queries by injecting DbContext into your controllers or services and executing .ToList(), .FirstOrAsync(), or .Where() chains

Code

// 1. Define your entities
public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int CategoryId { get; set; }
    public Category Category { get; set; }
}

public class Category
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection<Product> Products { get; set; }
}

// 2. Create DbContext
public class AppDbContext : DbContext
{
    public DbSet<Product> Products { get; set; }
    public DbSet<Category> Categories { get; set; }

    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        modelBuilder.Entity<Category>()
            .HasMany(c => c.Products)
            .WithOne(p => p.Category)
            .HasForeignKey(p => p.CategoryId);
    }
}

// 3. Register in Program.cs
var builder = WebApplicationBuilder.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(connectionString));

// 4. Use in a service or controller
public class ProductService
{
    private readonly AppDbContext _context;

    public ProductService(AppDbContext context)
    {
        _context = context;
    }

    public async Task

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Category.NET / C#
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
dotnetef-coreorm

Install command:

curl -o ~/.claude/skills/dotnet-ef.md https://clskills.in/skills/dotnet/dotnet-ef.md

Related .NET / C# Skills

Other Claude Code skills in the same category — free to download.

Want a .NET / C# skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.