Sample code:
static async Task Main(string[] args)
{
using (var context = new DBContext())
{
await context.Objects.Add(new Level
{
Id = 1,
Name = "Name 1"
});
}
}
Creates error:
Objects does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'Objects' could be found.
It's TPH database, Objects is class at the top of hierarchy.
I have no idea how to fix it, i'm not sure why it doesn't work here. I have heard it can be issue with using older C# (i don't use 8.0 because i'm unable to upgrade it).
DbSet<T>.Add(T)does not return aTask. If you want to persist what you have added to theDbSet<T>then callDbContext.SaveChangesAsyncand await the resultingTaskthat this call returns.i'm not sure why it doesn't work hereit wont, there's no task returned as mentioned already. Looking at that code, there's honestly no reason to even try and await it.)inAdd(new Level(that's missing, it's the close forAdd.