eBooks
eBooks copied to clipboard
[Book Feedback]
Please provide the title of the book - BLAZOR For ASP.Net Web Forms Developer
What do you think could be improved in this book? The section for working with data could be improved. It devotes most of the section to Entity Framework, but EF is not the only ORM that is out there as well as it is not the only ORM that can be used with BLAZOR. In fact, most ASP.Net applications that would be migrated would not be using EF. Why not demonstrate how an ORM such as Dapper could be used instead?
Also, a section on how to implement unit testing would be nice.
What do you like about this book? What I like about the book, is that it is a single point of looking up how to do this or that in BLAZOR, without going on the Web and reading out of date information.
Additional context As I have already started a BLAZOR project using Dapper and AutoMapper connected to the North Wind database.
Dapper – AutoMapper
Adding Dapper To a Project
- Install the software into the Project that will have the Data Services
Install the / a Dapper package into the project
Install System Data SQL Client
- Configure The Connection String for the project
Add the connection string to the “appsettings.json” file. You can get the base connection information from the SQL Server Object Explorer, under the properties for the server. Then modify it for the name of the database.
In this example, we are using integrated security. In a real world application, the ID and Password will need to be stored into something like a key safe.
In the Startup file, add a public variable to hold the connection string, and the code to read it in from the app settings file.
public string NothWindConnection = string.Empty;
NothWindConnection = Configuration.GetConnectionString("NorthWind");
In the Startup file you need to configure the DI for not only the Data Base Services, but also to add the connection string to those services.
For the Database Services, the connection string can be stored in a private variable.
- Use Dapper for Reading and Writing to the Database
In the example above, “Query” is like an extension method of the ADO “Connection” object. In one line, the query is run and the data is returned as data object.
In this example, a stored procedure is executed and we are using a single parameter.
Adding AutoMapper to the Project
-
Install the software into the Project that will have the Application Services
-
Configure The Environment
Add AutoMapper as a service to the service collection
Add a configuration file for all of the mappings
Here a base class is created, as all application services will be using AutoMapper
In the example above, this application service has two services injected. The database service and AutoMapper.
- Use AutoMapper for copying the DTO to the application service
In this simple example, data is passed through without any processing such as filtering or sorting.
Hi @dlevitan6623, thank you so much for sharing your feedback. Due to bandwidth and maintainability, we have kept this item a low priority. But if anyone in the community wants to give this a try, we will be happy to link the sample in the wiki.