Dlaczego EF 6 wysyła zapytanie do bazy danych dla wszystkich rekordów z następującym kodem?DbSet <T>. Gdzie (gdzie) .ToList() - dlaczego SQL nie zawiera klauzuli where?
public virtual List<T> Find(Func<T, bool> where = null)
{
_db.Configuration.LazyLoadingEnabled = false;
if (where == null) throw new NullReferenceException("The 'where' parameter of the Repository.Find() method is null.");
return _dbSet.Where(where).ToList();
}
wygeneruje następujące wyniki
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Sequence] AS [Sequence],
[Extent1].[Description] AS [Description],
[Extent1].[Instructions] AS [Instructions],
[Extent1].[WorkCenterOperationId] AS [WorkCenterOperationId],
[Extent1].[JobId] AS [JobId],
[Extent1].[JobAssemblyId] AS [JobAssemblyId],
[Extent1].[RowVersion] AS [RowVersion]
FROM [dbo].[JobOperations] AS [Extent1]
dwa pytania:
- Dlaczego nie jest kwerenda wykonana z WHERE?
- Jak uzyskać wykonanie kwerendy za pomocą instrukcji where?
Z pytania na temat: Jaki jest cel ustawienia domyślnej wartości 'null' dla parametru' where'? – DaveParsons
Nie ma. :) Wciąż edytuję metodę i klasę, której jest częścią. Pierwotnie miałem pomysł użycia jednej instrukcji find z opcjonalną klauzulą where, ale wybrałem osobną metodę FindAll(), ale nie usunąłem domyślnej wartości Find. Dobre pytanie. –