Title: Dataaccess
1Data-accessO/R mappingFrans Bouma, C
MVPSolutions Designhttp//www.sd.nlhttp//www.L
LBLGen.com
2Agenda
- Q What is data-access?
- Q What are the options for implementing
Data-access? - Q What is Object/Relational (O/R) mapping?
- Q What is code-generation?
- Demonstration O/R mapping / code generation
3Q What is Data-access?
A The way in which data is made available in a
software application.
Business Logic
DAL service
Data Access Logic
RDBMS (Oracle/SqlServer)
RDBMS (Oracle/SqlServer)
4- encloses among other things
- Logic for the (indirect) usage / manipulation of
data in external databases - Access point(s) to DB access functionality for
the other elements in the applcation (Database
abstraction) - Data-transport objects for the storage of data
in-memory (e.g. Dataset, Entity class etc.), with
or without behavior.
Business Logic
DAL service
Data Access Logic
RDBMS (Oracle/SqlServer)
RDBMS (Oracle/SqlServer)
5Q What are the options for implementing
Data-access?
- Top 3 (in no particular order)
- Table approach tables / SQL are the cornerstones
- Entity approach abstract Entity and
Relationships are the cornerstones - Domain model approach domains are the
cornerstones
6Q What are the options for implementing
Data-access?1 Table approach
- Characteristics are (among other things
- Users think in terms of tables, table fields,
FK/UC/PK constraints - Users think in terms of SELECT FROM table WHERE
/ INSERT INTO etc. - Users think in terms of sets of tableized data.
- In memory, data is stored in table-style
containers - All business rules are defined externally.
- Known tools / elements
- Datasets
- Stored procedures
- Raw ADO.NET classes, like SqlCommand/SqlDataAdapt
er - Enterprise Librarys DAAB / VS.NET dataset
functionality.
7Q What are the options for implementing
Data-access?2 Entity approach
Relational model (tables, constraints etc.)
Entity class model
NIAM/ORM model
8Q What are the options for implementing
Data-access?2 Entity approach
- Characteristics are (among other things)
- Users think in terms of abstract entities, like
Customer, Order - Users think in terms of relationships between
entities - Users think in terms of sub-sets of entities
retrieved from supersets, defined by filters. - In memory, data is stored in entity objects
(instantiations of entity classes) - Entity-oriented business rules are defined
internally, cross-entity business rules are
defined externally. - No supertype/subtype hierarchies based on solely
behavioral differences
- Known tools / elements
- Entity classes (aka Custom classes)
- Stateless Business logic classes with behavior
(cross-entity) - O/R mapping engine
- LLBLGen Pro
9Q What are the options for implementing
Data-access?3 Domain model approach
- Characteristics are (among other things)
- Users think in terms of Domains, like
Customer, Order an entity behavior - Users think in terms of relationships between
domains - Users think in terms of sub-sets of
domain-instances retrieved from supersets,
gedefinieerd by filters - In memory, data is stored in domain objects
(instantiations of domain classes) - All business rules are defined internally, also
cross-entity business rules. - Can have Supertype/subtype hierarchies based
behavior differences
- Known tools / elements
- Domain classes (aka Custom classes)
- Stateful Business logic classes with behavior.
- O/R mapping engine
- nHibernate, DataObjects.NET
10Q What is Object/Relational mapping?
A defining a semantical connection (mapping)
between a class element (field, property) and a
datasource element (table field, view field).
public class Foo private int
_bar //... public int Bar get return
_bar set _bar value //...
CREATE TABLE Foo ( -- ... Bar int
NULL, --... ) ON Primary
Mapping
11Mapping data is stored in so called Meta data,
which is used by the O/R mapper engine to realize
the mappings at runtime.
Application
Object
Data
Data
O/R mapper command
Data
O/R mapper
Meta- data
RDBMS (Oracle/SqlServer)
SQL
Example flow of an O/R mapper in action
(abstract)
12Together with the object data and the O/R mapper
command, the meta data is used to generate SQL,
at runtime, which is ran on the datasource. The
data which is returned eventually by the
datasource is then transported to the object or
objects initiating the cycle.
Applicatie
Object
Data
Data
O/R mapper command
Data
O/R mapper
Meta- data
RDBMS (Oracle/SqlServer)
SQL
13The meta data can be stored in XML, defined as
attributes on class elements or generated in code
so its mixed with the O/R mapper command
automatically.
Applicatie
Object
Data
Data
O/R mapper command
Data
O/R mapper
Meta- data
RDBMS (Oracle/SqlServer)
SQL
14Q What is code-generatie?
A generating code text using meta data and
templates
Here, meta data could be the same meta data as
used by the O/R mapper engine or new meta data,
for example retrieved from an XML file or by
reading a database schemas meta data.
Meta- data
Meta- data
Template
Meta- data
Meta- data
Meta- data
Code file
Code generator
Code generation can help with creating the
entity/domain classes and code for the O/R mapper
engine commands
15Demonstration O/R mapping / code generation
16More information LLBLGen Pro
http//www.llblgen.com O/R mapping
http//www.agiledata.org/essays/mappingObjects.htm
l My blog http//weblogs.asp.net/fbouma