9.14、EF Core 高性能
数据库操作是线上系统的核心,对系统的响应快慢也起着根本性的作用。
高性能建议
// Create an explicitly compiled query
private static Func<CustomerContext, int, Customer> _customerById =
EF.CompileQuery((CustomerContext db, int id) =>
db.Customers
.Include(c => c.Address)
.Single(c => c.Id == id));
// Use the compiled query by invoking it
using (var db = new CustomerContext())
{
var customer = _customerById(db, 147);
}将DbContext分成多个子DbContext
启用行版本控制功能
最后更新于