Database Reference
In-Depth Information
Code-first EF
For many of the samples, data needs to be set up in the database. The preference in this
topic is to use ORMs than SQL Scripts and EF is a Microsoft framework that supports in-
tegration into Visual Studio. For some of the samples, we plan to read and write data to
nservicebus , and other databases, using EF and MVC.
One of the tables that we will use is to load messages through the saga system. These mes-
sages would normally be the result of users populating MVC forms as they enter orders,
payments, or more.
The table will appear as follows:
We have discussed that there is no need to create many pieces manually, and we would use
EF to perform some of these functions. We will log, audit, automate, and check things as
much as possible.
Code-first EF utilizes the generic DbContext as we have mentioned in previous chapters.
Here, we will extend it so that it is database specific. The DbContext is a generic data-
base context used to perform operations on the database. A DbContext article for work-
ing with can be found at http://msdn.microsoft.com/en-us/data/jj729737.aspx . We will ex-
tend the DbContext so that it knows the sets of databases we will be creating to handle.
To specify the connection string or base database, see ht-
tp://www.entityframeworktutorial.net/code-first/database-initialization-in-code-first.aspx to
create DbSet . We will create a project called ConsoleDbContext to populate the ne-
cessary tables.
Search WWH ::




Custom Search