Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the DAO Pattern Widely Used in .NET?

Tags:

c#

.net

dao

Is the DAO—Data Access Object—a commonly used pattern in .NET? I've always used DAOs as a way to provide access to my data layer. For example I might have a thin interface over my EntityFramework ObjectContext exposing all of my ObjectSets as IObjectSet.

Complex queries would then be exposed by DAOs, each of which with a dependency on this interface. I might have a ProductDAO that exposes methods like GetProductsOnSale() or GetInfrequenlySoldProducts(). My controllers or presenters would then use these methods, which would likely be virtual to allow stubbing specific results for unit tests.

So is this a commonly used idiom in .NET? For some reason the overwhelming majority of examples I see online using this pattern are based on Java. Even this question on DAO best practices is tagged as Java and not C#.

There's nothing wrong with using something from another community, I just have a slight fear that everyone around me is doing things differently...

like image 854
Adam Rackis Avatar asked Apr 26 '11 19:04

Adam Rackis


1 Answers

It is a common idiom in .NET. I have used it and have seen it used in many places.

It is built into the framework - see the System.Data namespace - many of the classes are base classes for specialized providers (SQL Server, Oracle, MySQL etc...) and operations are executed on the base classes.

However, what you are describing sounds more like the Repository Pattern to me, not simply the use of Data Access Objects.

This is also used in many projects, though is not built into the framework.

like image 197
Oded Avatar answered Oct 12 '22 01:10

Oded