Database Reference
In-Depth Information
Figure 2-9. Our completed model
Figure 2-9 shows the new model created for us by including the Poet, Poem, and Meter tables as well as the
vwLibrary view.
You now have a model that you can use in your code. Note that the vwLibrary entity is based on the vwLibrary
view in our database. In most databases, views are read-only objects: inserts, deletes, and updates are typically not
supported at the database layer. This is also the case with Entity Framework. Entity Framework considers views read
only. You can get around this by mapping stored procedures for the create, update, and delete actions for view-based
entities. We will show you how to do just that in Chapter 6.
How It Works
Let's look at the model created for us by the importing process. Notice that the entities have scalar properties and
navigation properties. The scalar properties map to the columns in the tables of the database, while the navigation
properties are derived from the relationships between the tables.
In our database diagram, a poem has a meter and a poet (the author). These correspond to the Meter and Poet
navigation properties. If we have an instance of a Poem entity, the Poet navigation property holds an instance of a Poet
entity, while the Meter navigation property holds an instance of a Meter entity.
A poet can be the author of any number of poems. The Poems navigation property contains a collection of
instances of the Poem entity. This collection can be empty, of course, for those poets that have yet to write any poetry.
For the Meter entity, the Poems navigation property is also a collection. For this navigation property, the collection
holds instances of Poems that have the given meter. SQL Server does not support relationships defined on views, and
our model reflects this with an empty set of navigation properties on the vwLibrary entity.
Notice that the Import Wizard was smart enough to pluralize the navigation properties that contained collections.
If you right-click the entities and look at their properties, you will notice that the entity set names for each of the
 
Search WWH ::




Custom Search