---
title: "Implementing A Data Layer"
url: "https://osherove.com/blog/2003/5/12/implementing-a-data-layer.md"
canonical: "https://osherove.com/blog/2003/5/12/implementing-a-data-layer.html"
published: "2003-05-12T17:25:00"
updated: "2003-05-12T17:25:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "Ted Posts about ways to implement a Data Layer. I never liked Data Layer generators myself. They never actually did a good job. I fear I've become a sort of \"Generator-Bigot\" because of my past experiences with them. In…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Implementing A Data Layer

By Roy Osherove May 12, 2003 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published May 12, 2003; technical details may be outdated.

Ted [Posts](http://dotnetweblogs.com/tgraham/posts/6923.aspx%5d) about ways to implement a Data Layer.

I never liked Data Layer generators myself. They never actually did a good job. I fear I've become a sort of "Generator-Bigot" because of my past experiences with them. In my solutions (as well as some other solutions I know of) I use the Microsoft Application Blocks Data Layer Block. It is not a perfect piece of code, since it is fitted for the sqlClicent Namespace, but after refactoring it for an hour, I managed ,without too much fuss, to make it use strictly Interface based approach meaning it can now, beneath, use any compliant data source. (This is something I've learned from [Addy Santo's](http://dotnetweblogs.com/ASanto/) previous team - they use the same type of solution in their data layer)

A great benefit you get with that, is a very handy helper class, that actually does dynamic filling of parameters, but then it goes further - it **caches** them for re-use. the result is you pay the penalty of round-trip generation only once per stored procedure. the next time you call it - you're all set to go.

As for generating the stored procedures - What I do is create a throwaway project, and start dragging data adapters from the Server explorer onto the design surface. You can then tell the wizard to automatically generate Create,Insert,Update and Delete stored procedures for you. then you just throw away the project, and you get to keep the automatically generated procedures!

The larger up side to not using Automatic generators is that you keep control of what's happening. It scares me (Maybe I shouldn't but I am) to think of using such a generator, and then one day , for some reason (And they occur, don't they..) , I'll  need to do something in the data layer, something that is not supported by the generator. Now I'll need to read code generated by a machine, which is not bad by itself, except for that horrible learning curve (That's the good case - where the code is even half-readable).

Perhaps I'm mistaken with the new generation of code generators that's coming out, But if I am - prove me wrong. I'll be the first to use it if I'm convinced (It's not that I'm an early adopter as much as I'm plain lazy! I want something else to do the dirty work for me just like the next guy..)

I can also recommend a good book that depicts building a solid foundation for a 3-tierd application. Although it deals with building a web application - the parts about the Data Layer and the Business layer are by themselves worth more then the cost of the book . **Any developer** wanting to learn a good way of doing 3-tiers will benefit from reading it . It's called [**ASP.NET Website Programming: Problem - Design - Solution C# Edition**](https://www.amazon.com/exec/obidos/tg/detail/-/1861006934/qid=1052590666/sr=8-1/ref=sr_8_1/104-0728248-0448757?v=glance&s=books).

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- May 12, 2003

    ### [New Article: Practical Parsing Using Groups in Regular Expressions](https://osherove.com/blog/2003/5/12/new-article-practical-parsing-using-groups-in-regular-expres.html)

- May 12, 2003

    ### [More Books On My Shelf](https://osherove.com/blog/2003/5/12/more-books-on-my-shelf.html)

- May 12, 2003

    ### [About Design Patterns](https://osherove.com/blog/2003/5/12/about-design-patterns.html)

- May 11, 2003

    ### [Free Book Chapters](https://osherove.com/blog/2003/5/11/free-book-chapters.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
