-
Notifications
You must be signed in to change notification settings - Fork 44
SetupSecondaryData
There are times when you need to provide the user with extra information when creating or updating a database entry. This is where the EfGenericDto virtual method SetupSecondaryData
is really useful.
A good example is SampleMvcWebApp Create Post - lick the link to go to that page. You will see it has two lists:
- Bloggers, which is a dropdownlist of possible authors for the post.
- Tags, which is a multiselectlist of tags to go with the new post.
If you look at the code for the DetailPostDto.cs you will see that it overrides quite a few of the methods. I won't go through it in detail, but to give you an overview:
-
SetupSecondaryData
is overridden to produce the data needed to display the possible Bloggers and Tags. -
CreateDataFromDto
andUpdateDataFromDto
are needed to take the user's selection and convert it back to the form the database needs.
- NewOrderDto.cs - simply setting a dynamic variable.
-
CreateLineItemDto.cs - the DTO needed to grab the DbContext and
SetupSecondaryData
provides it.
As a safety precaution the default SetupSecondaryData
will throw an exception if called. That way I cannot forget it. If you don't need SetupSecondaryData
then set you need to set the flag DoesNotNeedSetup
in the SupportedFunctions
property. See CrudCustomerDto.cs for an example.
Live example web sites!
Introduction/Overview
Commands and options
- Introduction to Commands
- Key interfaces
- Calculated properties
- DoNotCopyBackToDatabase attribute
- Configuration Options
Data Transfer Objects (DTOs)