Skip to content

RazorPageApp

Jon P Smith edited this page Apr 7, 2018 · 11 revisions

The GitHub repo contains an example ASP.NET Core Razor Pages application. If you clone the EfCore.GenericServices repo and press F5 then it will start. It uses a SQLite in-memory so that it will run anywhere (Windows, Mac and Linux), and always starts with a known set of data.

NOTE: I use the term DTO (also known as a ViewModel) to mean a class containing a set of read/write properties that has been mapped to an entity class via the ILinkToEntity<TEntity> interface.

Where the GenericServices commands are used

The example application uses a mixture of approaches so that you can see them in action. Here are the examples of various commands.

1. ReadManyNoTracked<T>

There are two uses of this. The simplest is ReadManyNoTracked<AuthorWithBookCountDto> in Author\Index.cshtml.cs which just shows the Author's name and the number of books they have authored.

The Book list is more complex, and can be found in Home\Index.cshtml.cs It uses ReadManyNoTracked<BookListDto> method to produce the Select part of the query. This particular query needs a PerDtoConfig class called BookListDtoConfig to set up the AutoMapper Read mapping to get it to work.

2. ReadSingle<T>(keys)

This is used in many of the update methods to show the initial display needed for an update. There are two forms: using an entity class or using a DTO.

I use one mapped to an entity class (Author) in ???

There are many examples using the DTO version. Have a look at /Home/AddReview.cshtml.cs, or any of the update in the Pages/Home directory.

3. UpdateAndSave(entityOrDto)

This command will apply an update to an entity.

4. CreateAndSave(entityOrDto)

5. `DeleteAndSave(

Clone this wiki locally