Created
May 18, 2020 18:03
-
-
Save JeremyLikness/6c10d30b9477afc4e01beb4eb3915e73 to your computer and use it in GitHub Desktop.
Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 useGetAddressBookAsync
(I have yet to learn why it's needed forGetAddressBook
and not forGetAddressBookAsync
, but it works). I updatedPerson
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 withGetAddressBook
and not withGetAddressBookAsync
. The error I get is 'no suitable method found to override'.