-
Notifications
You must be signed in to change notification settings - Fork 42
Introduction to Commands
The primary job that GenericServices does is standardise the interface between the User Interface (UI) and the database using Entity Framework (EF). GenericServices provides commands for List, Detail, Create, Update and Delete of data. All the commands apart from Delete can work either directly with the database (EF) classes or via Data Transfer Objects - DTOs.
Each command, apart from Delete, can work with either a database (EF) classes or a DTO. See the section called Why DTOs? to hear why DTOs are so useful.
The commands work out whether the type/class you provided is one or the other of these and takes appropriate action.
- If the given type inherits from EfGenericDTO/EfGenericDTOAsync then it will do certain transformations on the data. See PostsController for example of using DTO with commands.
- Otherwise it assumes the given type is a database (EF) class and then directly accesses that data. See TagsController for example of direct access to database class.
Entity Framework validates all the data before it writes or updates the database. If this validation fails it throws an exception. Other validation is done by SQL Server, again throwing an exception. Other issues, such as trying to read a entry that is no longer in the database is another issue that can throw an exception.
GenericServices tries to provide superior error checking and reporting back to the user. It does this by intelligently capturing all these exceptions and errors and returning a status with human readable messages from each of its commands. Please see the description of the ISuccessOrErrors interface for more information.
All the commands support both synchronous (sync) and asynchronous (async) access to the data. Async has become fairly easy since .NET 4.5 and provides better scalability for web applications. Examples are:
- Data class (Tag), sync TagsController
- Data class (Tag), async TagsAsyncController
If you don't know anything about async/await in MVC then I recommend
- this video by Rowan Miller for why async is useful.
- My article The .NET 4.5 async/await feature in Promise and Practice
Live example web sites!
Introduction/Overview
Commands and options
- Introduction to Commands
- Key interfaces
- Calculated properties
- DoNotCopyBackToDatabase attribute
- Configuration Options
Data Transfer Objects (DTOs)