Databases Reference
In-Depth Information
Regardless of the approach you choose to developing your entity model—database-first,
model-first, or code-first—you want to minimize the amount of work you spend on the
secondary model. In other words, if you start by developing the database model first, you
want to spend the least amount of work on maintaining your conceptual model and
application classes. Likewise, if you start by developing the application classes first, you
want to spend as little time as possible tweaking the database tables the Entity Framework
generates for you.
The best way to keep the conceptual and storage models in sync over the life of the appli-
cation is to reduce the differences between them. Ideally, you want to be able to regener-
ate your entire secondary model without having to make any tweaks manually. This could
require introducing some of the database principles in the class design or taking object-
oriented principles into account when designing the tables. For instance, you might want
to sacrifice some of the normalization rules or break some of your DBA's favorite naming
conventions to make the generated classes easier to use in a .NET language.
This advice might feel counter-intuitive and go against the selling points of the O/R
mapping frameworks in general and the Entity Framework in particular. It is based on the
lessons learned in real-world projects and realization that additional flexibility rarely justi-
fies the added cost of troubleshooting problems caused by modeling mistakes and confu-
sion caused by the differences between the models. Unless your project has an unlimited
budget, you want to avoid paying this price until it becomes a true necessity.
Default Property Values
Setting default values of entity properties presents a surprising challenge in the Dynamic
Data applications. Although the Entity Framework allows you to specify default values
directly in the model, the Dynamic Data metadata API ignores this information. Figure 9.5
shows an example of setting zero as the default value of the UnitsInStock property of the
Product entity in the Properties window of Visual Studio.
FIGURE 9.5 Setting default property value with Entity Designer.
 
 
Search WWH ::




Custom Search