Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

My question is where it is more logical to write the queries in the data acess layer or business layer???
please answer

Regards,
Amol
Posted

Hi,

Data Access Layer normally contains the configuration related to Database connections like connect to SQL Server, MySQL or Oracle etc.

In Business Layer, you can create few folders/Namespaces like Entity (if using ORM concept), Service layer and Implementation layer.

And in this way you implement the loose coupling in the software design.

Changing in database (Migrating from SQL server to Oracle) will only impact Data access Layer and few impact on Business Layer as Stored procedures or queries may be DB dependent.

I hope, this will clear your doubt.
Please reply your suggestion if you are not agree with me.

Regards,
Jitendra
 
Share this answer
 
I believe you already know the answer to this. The usual place to write your queries is in the data access layer (that's why it's called that). There's nothing wrong with transforming data in the business layer, but actual access to whatever datastore you like should be accomplished in the DAL.

There are numerous reasons to do this, but here are a couple of my favourites:

1. You can test your business logic without requiring database access. If you have a loosely coupled application, then it's simple to put a mock object in place to simulate your data access.
2. If you need to target multiple database vendors, the only thing you may need to change would be your DAL (note that this doesn't apply if you are using an ORM tool such as nhybernate to hydrate your data model).
 
Share this answer
 
IMO, the Data access layer - however, others may have their own views.
 
Share this answer
 
It is better to write the SQL queries as StoreProcedure and then use your data access layer to call those storedprocedure by passing parameter.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900