I am wondering how do I change this statement to be async?
var findBarCode = context.Barcodes
.Where(x => x.Code == barcode)
.Select(x => x.Product).FirstOrDefault();
I don't see like any async where
statement I can use.
AsQueryable()); c# linq.
SaveChangesAsync() returns the number of lines changed. It is possible (at least theoretically) that two user will simultenously work to delete the same id in the database.
ToListAsync(IQueryable)Creates a List<T> from an IQueryable by enumerating it asynchronously.
FirstOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken) Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.
There's an extension method called FirstOrDefaultAsync
in System.Data.Entity
:
using System.Data.Entity;
...
var findBarCode = await context.Barcodes
.Where(x => x.Code == barcode)
.Select(x => x.Product).FirstOrDefaultAsync();
This requires Entity Framework 6.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With