IEnumerable' does not contain a definition for 'GetAwaiter' for Async Task Method

c# entity-framework-6

Accepted Answer

var db = new DatabaseContext();
    var results = await (from s in db.IntermediaryAssignment
                         where s.Dispatched == false && s.CompanyCode == 
                         company && s.RegistrationNumber ==
                          registrationNumber orderby s.StickerCode 
                         ascending select s).ToListAsync());

    return results.FirstOrDefault();
2
8/26/2018 1:08:00 PM

Popular Answer

var results = await (from s in db.IntermediaryAssignment
                         where s.Dispatched == false && s.CompanyCode == 
                         company && s.RegistrationNumber ==
                          registrationNumber orderby s.StickerCode 
                         ascending select s).FirstOrDefaultAsync();
    return results;

It is ideal to utilise if you want to pick the first item depending on the order.FirstOrDefault without ToList() & Take(1)

FirstOrDefault materialize the query and bring the first item from database.

ToList() if you need to get items based on your filter use to list.

In the situation you're in.ToList().Take(1); The ToList() instead of doing this, you may immediately grab the first item from the database using bring all data to memory and take the first one.FirstOrDefault



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