Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 15: Making controller action methods asynchronous #96

Open
Dreamoochy opened this issue Jul 29, 2022 · 2 comments
Open

Chapter 15: Making controller action methods asynchronous #96

Dreamoochy opened this issue Jul 29, 2022 · 2 comments

Comments

@Dreamoochy
Copy link

Sorry if I've missed something again. There's a code on the page 663:

HomeIndexViewModel model = new
(
  VisitorCount = (new Random()).Next(1, 1001),
  Categories = await db.Categories.ToListAsync(),
  Products = await db.Products.ToListAsync()
);

With = symbols I get CS0103 errors. Replacing them with : solves the problem:

HomeIndexViewModel model = new
(
  VisitorCount : (new Random()).Next(1, 1001),
  Categories : await db.Categories.ToListAsync(),
  Products : await db.Products.ToListAsync()
);
@markjprice
Copy link
Owner

markjprice commented Jul 29, 2022

I originally used a class with public properties where = would work. Late in the writing process, I switched to use records which require : instead because they are passed as named parameters instead of set as public properties. When on page 640 I tell the reader to enter that code for the first time, I correctly show the code using :, as shown in the following screenshot:

image

But later on page 662, I tell the reader to change the method to be asynchronous. At this point you only need to add the highlighted code and the original entered code does not need to be changed. But the code in the book mistakenly still shows the older = syntax, as shown in the following screenshot:

image

Hopefully most readers will not have been affected by this mistake since they are not told to change the : to = which causes your issue. But some will, so I have added an errata to warn them:

https://github.com/markjprice/cs10dotnet6/blob/main/errata.md#page-662---making-controller-action-methods-asynchronous

The repeated Index method code block also mistakenly misses out the logging statements and the attribute to control caching. Hopefully readers do not delete those too!

@Dreamoochy
Copy link
Author

There're a lot of quite big code blocks in the web-related chapters which are most probably intended to be copy/paste'd. It apparently becomes a habit for me. I hope other readers are more careful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants