Caverman
Caverman

Reputation: 3707

Entity Framework Core 6.03 .ToList() not available

I'm working on my first .NET 6 project and I'm using EF to run an inline query and creating a list of objects. However, I don't have .ToList() as an option; I only have .ToListAsync(). From doing a little research is looks like .ToList should still be available so I'm not sure what I'm missing.

This is what I have installed:

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
    <PackageReference Include="Oracle.EntityFrameworkCore" Version="6.21.5" />
  </ItemGroup>

Upvotes: 0

Views: 1133

Answers (1)

Guru Stron
Guru Stron

Reputation: 142123

Add using System.Linq; to the top of the corresponding file.

ToListAsync is an extension method for IQueryable coming from Microsoft.EntityFrameworkCore namespace while ToList is a framework build in method from System.Linq.

Another option is to set ImplicitUsings to enable in the .csproj file to leverage automatic import for default namespaces based on the type of project SDK (read more here and here):

<PropertyGroup>
   ...
   <ImplicitUsings>enable</ImplicitUsings>
   ... 
</PropertyGroup>

Upvotes: 3

Related Questions