Daily Archives: April 18, 2012

Data Access Layer – Get Art Collection Method

The following code snippet is the GetArtCollectionDataMethod(), from the ArtWorldCollectionArtPiece class, we discussed in the last post. This method demonstrates a practical application, of the separation of concerns concept, within a layered application architecture.

Within this one small method, we are utilizing all of the architectural layers;

    • This method performs a query against the entity data model, in the The Data Model Layer, which gives the application separation and independence from the data source.
    • The code in this method creates new instances of objects from the World of Art Domain, which are populated, or hydrated, with data obtained through the entity data model.

Do you remember how the entity data model maintains the one-to-many relationship, between the artist and their works of art? Even though the LINQ query is running against the WorksOfArt class in the object model, we not only have access to each work of art object, we also have access to the associated artist object as well.

Finally, this methods generates a generic list of objects from the World of Art domain. This list has a public access modifier, so it can be consumed by many different software clients. Each client can simply create a new instance of the ArtWorldCollectionArtPiece class, and all of the information needed, is in an enumerable generic list, for easy consumption.

Let’s wrap up our discussion of layered architecture and separation of concerns, by taking a look at the World of Art web app in the Visual Studio solution explorer;

Layered Architecture

Solution with layered architecture

The four architectural layers are highlighted in the illustration above;

  • The ArtWorldObjects class library is where the World of Art domain is abstracted into classes
  • The DataAccess folder in the WorldOfArtWebApp project contains the abstract interface for serving data to various clients
  • The DataModels folder contains the object relationship model, based on the Entity Framework
  • The Views folder contains the elements of the user interface