Persistent Object Management in less than 300 Lines of Code(codeproject.com)
submitted by
rcerff(160) 4 years, 10 months ago
There's a lot of repetitive work associated with the writing of data classes within the data access layer of an N-tiered architecture. Apart from adding a column to the relevant database table, adding a field to the class involves adding a private variable to hold the field value, a property to expose it to other classes, and several lines to make sure the field is included in insert, fetch, and update operations. If you're using stored procedures (very silly for CRUD queries) that several more modifications to make. This is dull work I'm sure you'll agree. Presented here is a lightweight method for taking away all this tedium, such that you only have to add a getter/setter property in order to add a field to a data class.
The technique involves abstracting SQL query writing and execution, and variable storage in data access classes to a base class. In the implementation presented here I've named this base class "PersistentDataObject". The "less then 300 lines of code" referred to in the title of this post are the lines of code in this base class, the database access class it uses, and a couple of exception classes used as markers to add clarity to exception origins. The complete code is included at the end of the post.
|category: ADO.NET
|Views: 7
tags:
Persistance DataObject ADO.NET another
Everyones tags:
Your Tags: