Database Reference
In-Depth Information
Code-first EF and configurations
As we have mentioned earlier, we can perform the configuration in code and outside the
app.config file. The app.config file comes in very handy, but sometimes the tech-
nical or non-functional requirements may require encryption of the configuration, or that
the configuration is more global by being entries in the database.
However, you may want to store this information in the database, as this shows user IDs
and passwords in plain text. This code will be found in the ConsoleDbCon-
text-Config directory.
We will walk you through a more extended example as it relates to NSB, just as we estab-
lished a relationship in the case of the previous DBContext with the app.config file.
In this scenario, we want to store the UnicastBusConfig settings in the database. The
unicast bus configuration is made up of a collection of message endpoints. So, we need a
one-to-many relationship in the configuration in the database that appears similar to the fol-
lowing diagram:
This shows a one-to-many mapping of the unicast configuration as it has a collection called
MessageEndpointMappingCollection of MessageEndpointMappings . This
is to allow many endpoint mappings in the app.config settings for unicast in the fol-
lowing code:
We can add many message endpoints. In order to create a database to hold these name-
value pairs, we will have to copy the UnicastBusConfig and MessageEnd-
Search WWH ::




Custom Search