Chuyển đến nội dung
Skillpedia
Lập trình chung40k · #7186

ef-core

Skill này làm gì

Agent này giúp bạn viết code Entity Framework Core tốt hơn và hiệu quả hơn. Entity Framework Core là công cụ làm việc với cơ sở dữ liệu trong C#.

Khi nào nên dùng

  • ✓Khi tạo hoặc sửa code dùng Entity Framework Core.
  • ✓Khi bạn muốn bảo đảm code nhanh và an toàn.
  • ✓Khi bạn gặp vấn đề về hiệu năng hoặc lỗi cơ sở dữ liệu.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/ef-core/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để tối ưu các truy vấn để tránh cơ sở dữ liệu bị chậm?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent so sánh code của bạn với bộ quy tắc và thực hành tốt nhất. Nếu tìm thấy điểm có thể cải thiện, nó gợi ý cách làm.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.

Câu hỏi thường gặp

Entity Framework Core là gì?

Đó là công cụ giúp chương trình viết bằng C# giao tiếp với cơ sở dữ liệu dễ hơn, mà không cần viết lệnh SQL phức tạp.

“Thực hành tốt nhất” là gì?

Đó là những cách làm được biết đến rộng rãi nhất, thường cho code nhanh hơn, an toàn hơn và dễ bảo trì hơn.

Tôi có cần biết nhiều về cơ sở dữ liệu để dùng không?

Không. Agent được thiết kế để giúp ngay cả khi bạn mới làm quen với Entity Framework Core.

Chi tiết

Mô tả gốc của tác giả

Get best practices for Entity Framework Core

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7186
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự