Skip to content

SetupSecondaryData

Jon Smith edited this page Jan 20, 2015 · 2 revisions

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:

  1. Bloggers, which is a dropdownlist of possible authors for the post.
  2. 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:

  1. SetupSecondaryData is overridden to produce the data needed to display the possible Bloggers and Tags.
  2. CreateDataFromDto and UpdateDataFromDto are needed to take the user's selection and convert it back to the form the database needs.

Other examples

Turn off SetupSecondaryData call

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.