Есть ли выгода для возврата нового запроса с помощью set> (). Почему бы не инициализировать его один раз в конструкторе?
Код: Выделить всё
using Microsoft.EntityFrameworkCore;
public class Customer
{
public int Id { get; set; }
public string? Name { get; set; }
}
public class MyFirstContext : DbContext
{
public IQueryable CustomersRO => Set().AsNoTracking();
public MyFirstContext() : base() {}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
// optionsBuilder.UseSqlServer(...)
}
}
}
public class MySecondContext : DbContext
{
public readonly IQueryable CustomersRO;
public MySecondContext() : base() {
CustomersRO = Set().AsNoTracking();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
// optionsBuilder.UseSqlServer(...)
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... he-context
Мобильная версия