I’m building an ASP web application and for the moment I have a namespace called Queries that contains the linq queries that are called from the code behind pages. The whole site will initially contain about 40 queries; more will be added later.
Should I keep all my queries in one large namespace or should I create a namespace for the queries of each page? For instance, QueriesPageA, QueriesPageB, QueriesPageC… and end up with about 10 smaller namespaces.
Thanks.
It sounds like you’re building a business logic layer.
If you’re using LINQ to SQL or Entity Framework, you will already have a collection of entity classes that closely represent your business domain.
I prefer to add my queries to entity classes as static methods. This keeps my queries neatly distributed (so I don’t end up with one huge business logic class) and easy to find (a query that retrieves a set of users will live in the User class).
If the query produces an aggregate or report (e.g. quantity of cookies sold grouped by year), then I usually create a new class for the report. That way, the report becomes a model in its own right, which works well in an MVC architecture, if that’s something you’re considering.