Skip to content

Override database access

Jon Smith edited this page Apr 21, 2015 · 2 revisions

There are some times when you need to override how GenericServices reads and writes to the database. As all the methods to do that are virtual then that is not a problem. Sometimes you just want to tweak something before or after calling the base method, but alternatively you can do the whole job yourself.

Below are some examples of where this might be used.

On create where you need to set some default data

Have a look at NewOrderDto.cs and its overriding of CreateDataFromDto

Using SecondaryData in Create/Update

In the Providing extra data example we had dropdownlists to help the user. When we create or update that data item we need to use the data coming back from those dropdownlists to fill in some of the data. See the overriding of CreateDataFromDto and UpdateDataFromDto in DetailPostDto class;

Domain-Driven Design (DDD) database

If you are using DDD it is pretty certain you will need to override the CreateDataFromDto and UpdateDataFromDto methods on many data classes. This is because a DDD design will not allow write access to some database properties, but instead provide methods or a static factory for create and update.

Handling special situations in Create and Update

Create and Update of data via DTOs is complex. I have written a long article about this subject on my technical Blog site, www.thereformedprogrammer.net .

Clone this wiki locally