Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created May 18, 2020 18:03
Show Gist options
  • Save JeremyLikness/6c10d30b9477afc4e01beb4eb3915e73 to your computer and use it in GitHub Desktop.
Save JeremyLikness/6c10d30b9477afc4e01beb4eb3915e73 to your computer and use it in GitHub Desktop.
Async
public override async Task<AddressBookList> GetAddressBookAsync(Empty request,
ServerCallContext context)
{
var objPersons = new AddressBookList();
var peopleWithPhoneNumbers = await _dataContext.People
.Include(p => p.Phones)
.AsNoTracking()
.ToListAsync();
// if PeopleList is an actual list, then instead of the code blow do this:
// objPersons.PeopleList.AddRange(peopleWithPhoneNumbers);
foreach(var person in peopleWithPhoneNumbers)
{
objPersons.PeopleList.Add(person);
}
return objPersons;
}
@JeepNL
Copy link

JeepNL commented May 19, 2020

Thank you for this example, this makes much more sense and I learned more about asynchronous vs. synchronous calls. I needed to delete override to use GetAddressBookAsync (I have yet to learn why it's needed for GetAddressBook and not for GetAddressBookAsync, but it works). I updated Person as well with the example from your tweet. I have a lot of catching up to do, due to personal circumstances I needed to take a break from programming (which lasted far longer than I initially thought: more than 10 years 😉). But again I'm learning new programming techniques as well, and as I mentioned in my tweet I like it very much. I'm older now, so it takes more time, but I don't mind.

Update
Oops, I spoke too soon. It's compiles, but doesn't run. I think override is needed. I'll figure it out, just takes some more time :)

Update II
For me learning programming again is now by trial and error mostly. Of course I can't delete override. But with 'override' it now only works with GetAddressBook and not with GetAddressBookAsync. The error I get is 'no suitable method found to override'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment