Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Apps and Services with .NET 7

You're reading from   Apps and Services with .NET 7 Build practical projects with Blazor, .NET MAUI, gRPC, GraphQL, and other enterprise technologies

Arrow left icon
Product type Paperback
Published in Nov 2022
Publisher Packt
ISBN-13 9781801813433
Length 814 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mark J. Price Mark J. Price
Author Profile Icon Mark J. Price
Mark J. Price
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Introducing Apps and Services with .NET 2. Managing Relational Data Using SQL Server FREE CHAPTER 3. Managing NoSQL Data Using Azure Cosmos DB 4. Benchmarking Performance, Multitasking, and Concurrency 5. Implementing Popular Third-Party Libraries 6. Observing and Modifying Code Execution Dynamically 7. Handling Dates, Times, and Internationalization 8. Protecting Your Data and Applications 9. Building and Securing Web Services Using Minimal APIs 10. Exposing Data via the Web Using OData 11. Combining Data Sources Using GraphQL 12. Building Efficient Microservices Using gRPC 13. Broadcasting Real-Time Communication Using SignalR 14. Building Serverless Nanoservices Using Azure Functions 15. Building Web User Interfaces Using ASP.NET Core 16. Building Web Components Using Blazor WebAssembly 17. Leveraging Open-Source Blazor Component Libraries 18. Building Mobile and Desktop Apps Using .NET MAUI 19. Integrating .NET MAUI Apps with Blazor and Native Platforms 20. Introducing the Survey Project Challenge 21. Epilogue 22. Index

Practicing and exploring

Test your knowledge and understanding by answering some questions, getting some hands-on practice, and exploring this chapter’s topics with deeper research.

Exercise 2.1 – Test your knowledge

Answer the following questions:

  1. Which NuGet package should you reference in a .NET project to get the best performance when working with data in SQL Server?
  2. What is the safest way to define a database connection string for SQL Server?
  3. What must T-SQL parameters and variables be prefixed with?
  4. What must you do before reading an output parameter of a command executed using ExecuteReader?
  5. What can the dotnet-ef tool be used for?
  6. What type would you use for the property that represents a table, for example, the Products property of a data context?
  7. What type would you use for the property that represents a one-to-many relationship, for example, the Products property of a Category entity?
  8. What is the EF Core convention for primary keys?
  9. Why might you choose the Fluent API in preference to annotation attributes?
  10. Why might you implement the IMaterializationInterceptor interface in an entity type?

Exercise 2.2 – Practice benchmarking ADO.NET against EF Core

In the Chapter02 solution/workspace, create a console app named Ch02Ex02_ADONETvsEFCore that uses Benchmark.NET to compare retrieving all the products from the Northwind database using ADO.NET (SqlClient) and using EF Core.

You can learn how to use Benchmark.NET by reading Chapter 4, Benchmarking Performance, Multitasking, and Concurrency.

Exercise 2.3 – Explore topics

Use the links on the following page to learn more details about the topics covered in this chapter:

https://github.com/markjprice/apps-services-net7/blob/main/book-links.md#chapter-2---managing-relational-data-using-sql-server

Exercise 2.4 – Explore Dapper

Dapper is an alternative ORM to EF Core. It is more efficient because it extends the low-level ADO.NET IDbConnection interface with very basic functionality.

In the Northwind.Console.SqlClient project, add a package reference for Dapper, and then add a class to represent a supplier, as shown in the following code:

public class Supplier
{
  public int SupplierId { get; set; }
  public string? CompanyName { get; set; }
  public string? City { get; set; }
  public string? Country { get; set; }
}

In Program.cs, add statements to retrieve Supplier entities in Germany, as shown in the following code:

IEnumerable<Supplier> suppliers = connection.Query<Supplier>(
  sql: "SELECT * FROM Suppliers WHERE Country=@Country",
  param: new { Country = "Germany" });
foreach (Supplier supplier in suppliers)
{
  WriteLine("{0}: {1}, {2}, {3}",
    supplier.SupplierId, supplier.CompanyName,
    supplier.City, supplier.Country);
}

You can learn more about Dapper at the following link:

https://github.com/DapperLib/Dapper/blob/main/Readme.md

I am considering adding a section about Dapper to the next edition of this book. Please let me know if this if something that I should prioritize. Thanks!

You have been reading a chapter from
Apps and Services with .NET 7
Published in: Nov 2022
Publisher: Packt
ISBN-13: 9781801813433
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime