Unable to identify where to enable the FirstOrDefaultAsync method for a ASP.NET Core model

asp.net-core c# dbset entity-framework-core razor-pages

Question

I'm having difficulty identifying where in a ASP.NET Core app we specify that a model can have the FirstOrDefaultAsync method enabled. I've previously scaffolded two models to razor pages, and for those I can write async method like so:

component = await Context.component.FirstOrDefaultAsync(m => m.ID == id);

However, for this new model that I scaffolded, I used a view Model but when I swapped the models, I get an error when I use the FirstOrDefaultAsync method.

'DbSet' does not contain a definition for 'FirstOrDefaultAsync' and no accessible extension method 'FirstOrDefaultAsync' accepting a first argument of type 'DbSet' could be found (are you missing a using directive or an assembly reference?)

I've made sure that the necessary namespaces have been included in the file, and the DBContext file includes the model

public DbSet<update> update { get; set; }

I made sure to run dotnet restore and restart VSCode and am unable to find answers searching online or in the documentation

1
1
3/10/2020 3:04:49 PM

Popular Answer

I thought I made sure I had all the include statements I needed, but somehow using Microsoft.EntityFrameworkCore; got deleted. Re-adding it resolved the issue.

3
3/10/2020 1:06:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow