C# Architecture – Data Layer vs Business Layer

cdatarepository

I think I'm in the minority on this but would be curious to see other perspectives.

A lot of times I see people talk about the Data Layer like having functions like UpdateCustomer() or Summarize(). I really feel like the Data Layer should be more abstract than that. I currently use a generic Repository pattern on top of entity framework in my data layer. So I get functions like Find(int id), Update(), Save(), All(), etc. Very generic functions.

Then I make Business Logic layers that have more specific functions like Summarize() that work on the generic Data Layer. For me just isolating the data access technology is enough for the Data Layer. That's a big enough job on it's own. Why provide these seemingly query functions in your Data Layer? The business logic I write a large part of the time is inside Linq queries themselves so for me all specific queries should be in the Business Layer and not the Data Layer, but this isn't what I often see.

On top of that, because my Data Layers are not very generic, I can share them, they are DLL's, with other Business Layers (often web services) so that I can combine very different pieces of data together in a Business Layer to join queries between the 2 (since I have generic access to the underlying data) and it also helps in not having to recreate Data Layers for each separate solution. To me it's great resuabiltiy.

I'm wondering what the opposite view is on my view here. Why am I "wrong" in thinking this way and why is the other way "right"?

Best Answer

It's a matter of definition of the terms Data and Business. Your perspective seems to be that the Data Layer is dealing with data generically and the Business Layer tells the Data Layer which data.

Another perspective is to consider the Data Layer as consisting of the collection/attributes of data classes and the Business Layer as consisting of the methods of data classes.

The only con I can think of with your approach is that the Business Layer can get a bit heavy.