Click here to Skip to main content
15,881,248 members
Articles / Database Development / SQL Server / SQL Server 2012

Arkitech Platform Framework

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
22 Jun 2015CPOL6 min read 11K   127   2  
The primary purpose of this article is to provide quality sample source code for VB.NET developers interested in building data-centric applications using the .NET Framework.

Image 1

Introduction

The Arkitech Platform Framework (APF) is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write. APF is a software development framework that helps you build a maintainable business logic layer when buiding Windows Forms (WinForms) Microsoft SQL Server (MSSQL) data-oriented applications. There are multiple data access frameworks in the .NET software development environment. This is an attempt to create a dyanamic database altering Business Logic Layer (BLL). What's different about this framework vs others is that it is a dynamically flexible UI.

Business logic changes all the time. These changes trigger automatic changes in the underlying database. This Platform enables you to create an object-oriented business layer that abstracts and encapsulates all of your business logic and data. The framework ensures that as your business objects change they will still work seamlessly. Any updates that occur within the BLL class(es) accordingly trigger updates to the underlying database.

The key benefit of utilizing the Platform is that it helps your application practically build itself.

  • No Code Data Access Layer - A Data Access Layer (DAL) builder that requires no code on your part, it builds itself at compile-time with a full object layer and strongly-typed collections.
  • Complete Toolset - A complete utility toolset, complete with Rails-like scaffolding, migrations (DB Versioning), and code generators.
  • Dynamic Query Tool - A dynamic query tool that lets you use SQL Server and the Enterprise Library without having to know SQL.
  • OR Mapper - An OR Mapper that extends to views and stored procedures so you're not locked into the OR/M thing.

Background

Arkitech Platform is VB.NET project that is very loosely based on Subsonic. Subsonic is a popular toolset of utilities that significantly speeds up development time for database driven web applications. SubSonic is a .NET open source project developed by Rob Conery and a core team of developers. There are also some general ideas used based on the CSLA.NET project by Rockford Lhotka. Other than that, there maybe other bits and pieces from code found around the internet(s).

Comparison

So whats the difference between this and Entity Framework (EF). EF is a 'code-first' framework. In this scenario, you don't have to bother with a database diagram, but simply write POCO classes that represent the objects you want to store. You then reference these classes in a special class called a DbContext to have EF persist them to a database. Microsoft added a key feature to EF that is only available with code first, which is migrations. Migrations let you change your data classes and then update the database without losing data.

APF Approach

With the APF approach you also have the benefit of 'code-first'. If you later refactor your code then your changes will get migrated to the data store 'on the fly'. However, the BIGGEST drawback for me with EF was in the DbContext class. The DbContext class in EF represents a combination Repository that it can be used to query from a database and group together changes that will then be written back to the store as a unit. In other words, in the DbContext class ALL of your data manipulation is done in one class file.

The DbContext class can also be a black box that is hard to debug; you have to trace the SQL that it generates and puzzle out why something is wrong. For those of us who often may need to go back and change one specific little item this can be quite irksome. I prefer the separation of the business classes and it's underlying data manipulation. In APF data manipulation is done by a specific 'Manager' class (i.e. TaskManager, PeopleManager, UserManager, etc.).

Also, APF follows the trend of why MVC is so popular. The separtion of business concerns means that View class assignments can be very class specific. No need to assign an entire DbContext to each View with all of its machinery. By not splitting code components you are very likely to introduce undesirable coupling between the concerns.

Image 2

Assumptions

This framework is generally targeted at the freelance ISV. One key assumption here is that the database is a new and/or existing database that you have Administrative rights to modify. Another assumption is that you use some type of database normalization when creating your database tables. The data classes presented here are as close to Fourth-Normal Form (4NF) as possible.

Image 3

Code Architecture

  • Mappings - APF uses customized Attribute-based Strongly-typed code mappings. This allows for keeping both the entities and database details on the same place. A strongly-typed code-based, allows for dynamic creation of the databasse model and strongly typing it, so that if, for example, a property name changes, the mapping will not be effected.

  • Associations - APF supports one to one, one to many and many to many.

  • Querying - APF exposes several querying APIs: LINQ is probably the most used nowadays, and really does not need to be introduced; The Platform API is an implementation of the Query Object pattern where you create a semi-abstract conceptual representation of the query you wish to execute by means of a class model using strongly-typed LINQ expressions instead of strings; this, is more refactor-friendlier than using a Criteria string.

Image 4

Platform Internals

FrameWorkConnection

APF relies on three primary classes for communication between the backend database and the frontend UI. For frontend UI you will Inherit from a Singleton FrameworkConnection class. The inherited class (ex. 'Database') is simular, in some respects - as a database repository, to the DbContext class. Each Manager class references this repository for CRUD its operations.

Image 5

Command Class

The Command Class is how APF does the business of interacting with the database. In this example the InsertCommand class contains a TableMapping Class that helps to break down the code object using metadata to retrieve raw data to be inserted into the SQL Server backend.

Image 6

Using the Code

The developer only needs to call methods contained in the Manager class for any CRUD operations.

VB.NET
Public Overrides Sub Create()
    Dim preCount As Integer = Count()
 
    Dim ParentID As Integer = 0
    Dim UserID As Integer = 1
    Dim StateID As Integer = 1
    Dim PriorityID As Integer = 1
    Dim CategoryID As Integer = 1
 
    Dim ProjectID As Integer = CreateProject.ProjectID
 
    Dim biz As Task = TaskManager.Default
    With biz
        .CategoryID = CategoryID
        .PriorityID = PriorityID
        .ProjectID = ProjectID
        .ParentID = ParentID
        .StateID = StateID
    End With
 
    TaskManager.Insert(biz)
    TestObject = biz
    CreateChildTask()
 
    TestObject = biz
 
    TestAssert.Equals(Count, preCount + 1)
End Sub

Interesting Tips

In the design phase of the AP Framework I found it neccessary to create a niffty SQL Server based set of extensions which are included in the sample.

Image 7

History

This project builds on the first project I started on CodeProject several years ago called TeamVision. For a primer on how to implement a framework into your application have a look at it here: TeamVision - A simple project task management application. A .NET managed approach to help keep on top of your projects.

References

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Arkitech EBC Corporation
United States United States
MS, BBA, software developer, consultant, and trainer. Specializing in building data-centric applications designed for business, university, community & faith based organizations. Started developing Excel VBA macros and never looked back. Freelance developer utilizing VB.Net, SQL Server, Microsoft Access, and ASP.Net.

Comments and Discussions

 
-- There are no messages in this forum --