Thursday, September 30, 2010

Incoming! ....awe Crud...

I don't know about any of you, but I've seen a lot of different data access components in the last couple years. Some people swear by ORM (Object Relational Mapping) suites like nHibernate, or use the Enterprise Library's data access application block. I've used both, but my experiences with both have been mixed.

So, I've decided, I'll write my own! My core concept I have in mind is that for every base business object, you should have an abstracted data access object. this object should handle all standard operations, such as Creating, Reading, Updating, and Deleting the given object (also known as CRUD). It should also provide the ability to get that object as a collection. Each of these methods can be provided additional parameters similar to how parameters are added to a command object. Once a CRUD call is made, the parameters are cleared, so that that new parameters can be added for the next call.

To define this concept, below is the interface describing what I expect any of these data access components to look like:


-----------------------------------------------
public Interface ICrud<T> where T:new()
{
    void AddParameter(string parameterName, object value);

    void Create(T objToInsert);

    void Read(T objToLoad);
    void Read(string customCommandName, T objToLoad);

    void Read(List<T> listToLoad);
    void Read(string customCommandName, List<T> listToLoad);

    void Update(T objToUpdate);

    void Delete();
}
-----------------------------------------------


I've already implemented the code base for an abstract version for SQL data access. But that is the next blog post!

No comments:

Post a Comment