Vous êtes sur la page 1sur 3

database and to make a model from it in our project is to

M. Herceg, S. Kovai, E. uli and M. Redipai

Database First vs. Code-First Approach in Software Design Workflows


Abstract A number of issues that present both of the simply add an ADO.NET Entity Data Model to it as an item.
common approaches in software design workflows are being
described in this paper, as well as the preferences of choosing Then the technology maps the database objects to entities
either of those for software development circle. Entity and represent them on the connected diagram that can be
framework is a common-used technology that saves developers updated with the changes needed in the database.
time for writing data-access code, avoids contacting the The conclusion of the Griffin's comparative research on
database directly, and it usually uses four different approaches Entity Framework vs. other traditional approaches can be
depending on whether you use an existing or a new database summarized as follows:
for your project. This paper is being focused on advantages and
disadvantages of the two approaches and give the key points It greatly reduces the time spent writing code for the
for making preferences when staring a new project of moving a applications data access layer, makes managing database
legacy project to a new database. This paper tries give new relationships and data objects easier, provides a level of
developers aspects to choose which approach to use for their abstraction to isolate the database from the developers
future software development, as well as to give insight why and application, and translates queries at runtime allowing
when to use any of the approaches mentioned above. It will also minimal code impact with regards to database storage
give a short insight of a new Entity Framework version 7 and changes. (Griffin, 2013)
future vision for entity framework development. Some authors call this approach Model first, even though
the model (.edmx) is generated from the database. Database
I. INTRODUCTION first approach with entity framework is easy to use and quite
logical when you have an existing database, but Oliveira
This paper gives an overview and critical points suggest five possible scenarios when you'd prefer using this
developer is thinking of while choosing the way he/she approach over other approaches for application development.
would approach to the development of a software product. In These, according to Oliveira would be when you have:
the first part database first approach will be explained as well 1. Long lasting databases with stable schemas
as the pros and cons of using it when developing a software
product. In the following chapter code first approach is 2. Changes to database and model are incremental
explained and compared to the database first approach. User
is directed which approach to use based on his/her 3. You want to be able to see your model in one diagram
preferences in developing a product as well as his/her and update from there
preferences about product release. Last part explains other 4. You can divide your model to non-overlapping
approaches, more precisely - design first approach which diagrams
focuses on owner(s) of the product and their preferences as
they take an important part in the development cycle of the 5. You have a database designed by DBAs, developed
product. This paper hopes to help the decision-making separately or if you have existing database (Oliveira,
process developer has to go through when starting the 2016)
development cycle of his/her software product.
Despite its advantages as using an existing database,
stored procedures and avoiding data loss new Entity
II. DATABASE FIRST APPROACH Framework 7 does not support .edmx approach or database
first-approach, but it rather introduces solely code-first or by
As most of the technologies are first invented to save some authors called code-based approach (since it can also be
developer's time by sparing them extra coding, the entity applied to existing databases so it'd be somewhat confusing
framework is invented for the exact same reason. Entity and unfair to call it code-first). In the database first approach
framework is Microsofts ORM (Object Relational Mapper) all entity classes inherit the EntityObject class and as such,
which automatically generates model code to be used in the will always be tightly coupled to the Entity Framework.
application. Database first approach allows us to reverse- More on Entity Framework 7 is being introduced in chapter
engineer a model from an existing database, meaning 2.
building a conceptual model from a database already made in
SQL. This model is generated as an .edmx file and the
classes that we need in our application are automatically III. CODE FIRST
generated from this .edmx file. The way to use the existing
Possible scenarios for using code- first design would be
when:
M. Herceg, Faculty of Information Technologies, "Demal Bijedi"
University of Mostaru, University Campus bb, 88104 Mostar, Bosnia and one prefers pure coding over design.
Herzegovina (phone 381-36-281040, e-mail: marija@fit.ba).S. Kovai,
University Information Centre, "Demal Bijedi" University of Mostaru, full control over database design without knowing too
University Campus bb, 88104 Mostar, Bosnia and Herzegovina (phone: 381- much SQL is preferred.
36-281040; e-mail: salko@unmo.ba).
E. uli, Faculty of Information Technologies, "Demal Bijedi" University new database is to be created and theres no existing
of Mostaru, University Campus bb, 88104 Mostar, Bosnia and Herzegovina one.
(phone 381-36-281040, e-mail: eminao@fit.ba).
M. Redipai, Faculty of Information Technologies, "Demal Bijedi" developer wants to cope with all modern application
University of Mostaru, University Campus bb, 88104 Mostar, Bosnia and projects.
Herzegovina (phone 381-36-281040, e-mail: muharem@fit.ba).
Code first approach is best suitable and used if you have Building application in a traditional way by coding first
already created domain classes, as with this approach you can make a lot of people with good idea to give up before
don't have to worry about auto-generated code. In this they even try to learn things prior to design.
approach your code defines and creates the database. A
typical entity class is given below which maps to the database Starting with design first can motivate people with good
objects is shown below: idea to start some project and learn something more about
programming later. If someone doesn't have skill to set code
public class Student alone, then he will be able to team up with someone who has
{ coding skills.
public int StudentId { get; set; } If someone with good idea and poor knowledge about
public string StudentName { get; set; } programming starts with design-first approach it is more
public DateTime StudentBirthDate { get; set; } likely that he will build application at the end in comparison
with someone who starts to build an application on
} traditionally way. This approach offers better opportunity to
design really good solutions for real-world problems
Two other steps to successfully generate a database is to (Douglas Kiang, 2015)
create a custom context extending the DbContext class and to
make a connection string in the configuration file. In this Someone who is end-user with good idea can start with
approach EF does not use any kind of configuration file to design-first approach and build design which other end-users
store the database schema, because the mapping API uses will also be familiar with. Sometimes we have good software
these conventions to generate the database schema solution when we consider from IT side, but when we
dynamically at runtime. The Code First Conventions are used consider it from end-user side, it can be hard to use. This
to discover how the conceptual model should be built and approach can avoid problems like that.
mapped and how to create a database storage model. These
Conventions include Primary Key, Relationship and Complex The design-first approach focuses on the human, without
Type Conventions and Type Discovery. influence from the data or the user requirements until a
visual concept is developed. This approach offers a fresh
Code first does not have a diagram showing the perspective that can enhance or be an alternative to
connected entities, nor some other visualization tool, which traditional visualization approaches, particularly for difficult
is the sources of many complaints on Entity Framework 7. visualization problems.
Code first is usually preferred when developers have no aim
in dealing with the database, and when the database can be We know that traditional visualization process begins
changed often, when the database is short-lived and when with the data. There are many definitions of data, but in this
scalable applications are being used. context, we refer to raw bits, bytes, text, and images typically
used in analytics rather than higher-level representations
Mombrea claims three exact and most important reasons
for using code first approach (with creating a new or using The relationships provided by the analytics are matched
the existing database) instead of other approaches in to visualization techniques suited to show those types of
application development when using entity framework. relationships. The final visualization is a combination of
Those according to Mombrea would be: visualization techniques, analytics, and data that support
human tasks. This data-first approach is the most common
1. less cruft, less bloat sometimes for an extra and accepted practice for visualization.
functionality when using DB-first approach you need
to extend the model class, and eventually you end up Visualizing particularly large and complex datasets for
extending everything. Additional files are burden analysis is one of several current research challenges in the
too. visualization community (Theresa-Marie Rhyne, 2015)

2. Greater control - you only have what you created. Visualization and teaming up with different software
You can control both your code models and your development skillsets helps build more useful products and
database design. Your responsibility is much higher, helps solve problems easier.
but its the price of more control. The benefit of the design-first approach is that it can
3. Database version control - by version controlling lead to new visualization innovations that are not
your source code you're helping to version your constrained by data. Provocative visualization concepts that
database. (Mombrea, 2014) are not yet possible may drive future technology
requirements. This approach is opportunity for innovation in
that new data and analytic technology requirements that
IV. OTHER APPROACHES solve user needs may be derived directly from the design. We
believe there are classes of problems for which the design-
Of other approaches used in software development first approach will yield better results than traditional
authors often refer to a design first approach as a new approaches. The design-first approach is especially
perspective in creating APIs. promising for new problems that do not yet have strong
First thing that we think about when we mention design- visualization solutions and it is also a great way to re-
first approach is that we are working something backward. examine visualization problems that have been investigated
Design-first approach starts with a design thinking approach for years without a suitable solution or significant
to creating an application, then proceed to a prototype, improvement. (Theresa-Marie Rhyne, 2015)
multiple iterations based on real feedback, and finally a top-
down approach to solving the coding problems.
For example, in most government organizations non-IT more abstraction. Also, if you want minimal code impact
people use client-server information systems which are very with regards to database storage changes its natural to
hard and complicated for them to use. Design-first approach choose database first approach.
maybe can help to re-examine visualization problems and
offer suitable solution and significant improvement. Using code first approach is more preferable if you want
more control over your code and your databases as well as
If we make comparison to other approaches we can more control over database versioning and more coding over
conclude that database-first approach is fastest way to build design, in the end.
application and code-first approach is for larger long term
projects because provides a better control for making Using design first approach helps to motivate children to
efficient program. Design-first approach may be slow learn more about programming as well as to help people
solution because we may not be able to implement every without necessary coding skillset to team up with ones that
feature that we like in that design, and we can get stuck in do to solve problems together and build meaningful apps
code doing that. (Mombrea, 2014) and software products.
When time is not important with design-first approach
we can implement some new ideas, and explore new
technologies easier. As we have said it is good approach for
re-designing some useful applications with poor design, and
good approach to use in educational purposes because it can REFERENCES
easily stimulate students to get involved, build teams and [1] Griffin, C (May 17th, 2013) A Comparative Look at Entity Framework
learn new things. Code First, La Salle University Digital Commons, La Sale University,
p.8. Retrieved on Sep 10th, 2016. from
When talking about collaborative design first approach http://digitalcommons.lasalle.edu/cgi/viewcontent.cgi?
using simple markup authors often suggest a platform called article=1010&context=mathcompcapstones
Swagger. According to a wide usage over last years and their [2] Oliveira J. (Sep 2nd, 2016) Database or Code First Approach -
Developer's Vision, retrieved on Sep 10th, 2016 from
official page Swagger is an open source framework backed by https://www.linkedin.com/pulse/database-code-first-approach-developers-
tools that help to design, build, document and consume APIs. vision-jader-oliveira?trk=eml-b2_content_ecosystem_digest-
1
A tool called Swagger Editor, for example is one of the core recommended_articles-111-
tools behind that offers instant visualization of the code null&midToken=AQGJ6egiz_k4GA&fromEmail=fromEmail&ut=0iYu
behind as showed in the following photo: mb-pqSHDo1
[3] Mombrea M. (Feb 14, 2014) 3 reasons to use code first design with
Entity Framework, Retrieved on Sep 28th, 2016 from
http://www.itworld.com/article/2700195/development/3-reasons-to-use-
code-first-design-with-entity-framework.html
[4] Theresa-Marie Rhyne (Feb, 2015) A "Design First" Approach to
Visualization Innovation, Retrieved on Sep 28th, 2016 from
https://www.researchgate.net/publication/270758644_A_Design_First_A
pproach_to_Visualization_Innovation
[5] Douglas Kiang (Nov 6, 2015), Coding by Design: A Design-First
Approach Retrieved on Sep 28th, 2016 from
http://www.edutopia.org/blog/coding-by-design-first-approach-douglas-
kiang

Figure 1 Swagger editor with instant visualization

APIs are often designed and documented after theyve been


development, Swagger is one of the tools that help to turn
the process around, to start first by designing the APIs using
simple markup.

V. CONCLUSION
In order to help developers first steps in creating a
successful software product while maintaining control over
database(s) and/or code this paper gave an insight to various
approaches that are available to the developers. Even
though, this paper mostly focused on traditional
approaches database first and code first approaches, new
approach is also introduced here called design first
approach.
Using database first approach is tightly coupled with
Entity Framework, and is often chosen when you have
existing databases created by DBAs with stable schemas and
1 http://www.swagger.io/

Vous aimerez peut-être aussi