Database Reference
In-Depth Information
Creating tables with EF
So far, the examples have shown us how to read messages in EF. We chose Entity Frame-
works to monitor and build SQL Server tables as Entity Framework works well inside
Visual Studio for modeling data. Also, using an ORM product eliminates SQL Injection as
there is no SQL code to review. Refer to http://www.slideshare.net/rhelton_1/sql-injection-
amp-entity-frameworks for more information on Entity Frameworks and SQL Injection.
Besides security concerns, EF is a recommended platform for programming C# into SQL
Server from Microsoft. Microsoft puts a lot of effort into both Visual Studio and the .NET
frameworks to make it as easy as possible.
In the next two samples, we will show you how to populate sample messages into SQL
Server tables to test some of our NSB deployments. EF is a very useful framework to gen-
erate code that will create tables and sample data, as well as read tables quickly for SQL
Server. In the next two examples, messages will be generated through two means, one be-
ing code-first EF where a model does not have to be created from an existing database, and
one via model-first where a model does have to created first from an existing database. In
both examples, the frameworks will be creating pay messages in the MVCAp-
p1.AppContext table as we go through a generic use. In the next chapter, we will create
the same messages in nservicebus .
The goal of both these examples will be to create a pay message table and populate it:
The main function in both programs to create the messages will also be the same, except
they will be calling a different context that is used to create the database and tables from
code-first or from the model-first.
The code-first program will be called from the MVCApp1 solution and the model first ex-
ample will be called from the MVCApp1-ModelFirst solution. The code-first solution
is so named as the MVCApp1 namespace is used in generating the database name.
We will start with the Program.cs file for both applications.
Search WWH ::




Custom Search