GetPizzasAsync does not contain a definition

Bill Mackin 0 Reputation points
2024-11-13T21:47:11.3+00:00

I'm following the tutorial where this is step 4:

https://learn.microsoft.com/en-us/training/modules/interact-with-data-blazor-web-apps/4-access-data-from-blazor-components

There's a code section that shows this:

namespace BlazingPizza.Data;

public class PizzaService {

public Task

Blazor Training
Blazor Training
Blazor: A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.Training: Instruction to develop new skills.
11 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pradeep M 4,560 Reputation points Microsoft Vendor
    2024-11-15T03:53:14.34+00:00

    Hi Bill Mackin,

    Thank you for reaching out to Microsoft Q & A forum.  

    It appears that the issue with GetPizzasAsync() is due to a missing return statement, which results in the error message 'PizzaService.GetPizzasAsync()': not all code paths return a value. This happens because the code section in the tutorial includes a placeholder comment (// Call your data access technology here), but doesn’t include a complete example with a return statement 

    To resolve this, you can add a temporary return value with some sample data. Here’s an example that will allow you to proceed without errors: 

    public Task<Pizza[]> GetPizzasAsync()
    {
        // Sample data to ensure the method compiles
        return Task.FromResult(new Pizza[]
        {
            new Pizza { PizzaId = 1, Name = "Margherita", Description = "Classic", Price = 9.99m, Vegetarian = true, Vegan = false },
            new Pizza { PizzaId = 2, Name = "Pepperoni", Description = "Spicy and savory", Price = 12.99m, Vegetarian = false, Vegan = false }
        });
    }
    
    

    This code provides placeholder pizza data, which can be replaced later with actual data from a database or other data source when you’re ready to integrate it. 

    Please feel free to contact us if you have any additional questions.    

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.         


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.