I'm wondering if it is correct to do some async operation in the following way.
Here is the sync classic code to get some data with a Find method:
public override Personne Find(object id)
{
return this.dbSet.OfType<Personne>()
.Include(a => a.Adresse)
.Include(c => c.PersonneCivilite)
.SingleOrDefault<MajeurProtege>(p => p.PersonneId == (int)id);
}
Well, no issue with that as it is classic.
Now to have the same method Async i can write it like this :
public async override Task<Personne > FindAsync(object id)
{
return await this.dbSet.OfType<Personne >()
.Include(a => a.Adresse)
.Include(c => c.PersonneCivilite)
.SingleOrDefaultAsync<MajeurProtege>(p => p.PersonneId == (int)id);
}
But is the following method do strictly the same thing ? As it could allow me to write my async method without code pasting my queries parameters.
public async override Task<Personne> FindAsync(object id)
{
return await Task.Run<Personne>(() => Find(id));
}