0

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>
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Caverman
  • 3,371
  • 9
  • 59
  • 115
  • I see no reference to Linq, is that normal? – Bechir Anoir Chabchoub Mar 15 '22 at 16:45
  • 1
    Thanks. That pointed me to what looks to have been the issue. I don't think you need Linq reference the packages file but I added "using System.Linq;" to the top of my DataManger page and it looks like I have ToList now. I've had that before and forgot about it. Too bad it doesn't show up as one of the suggestions in VS as how to fix. – Caverman Mar 15 '22 at 16:51

1 Answers1

3

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>
Guru Stron
  • 102,774
  • 10
  • 95
  • 132