在哪里写查询更合乎逻辑 [英] where it is more logical to write the queries

查看:92
本文介绍了在哪里写查询更合乎逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题是在数据访问层或业务层中编写查询更合乎逻辑吗?
请回答

问候,
Amol

解决方案



数据访问层通常包含与数据库连接相关的配置,例如连接到SQL Server,MySQL或Oracle等.

在业务层中,您可以创建几个文件夹/命名空间,例如实体(如果使用ORM概念),服务层和实现层.

并以此方式在软件设计中实现松耦合.

数据库中的更改(从SQL Server迁移到Oracle)仅会影响数据访问层,而对业务层几乎没有影响,因为存储过程或查询可能取决于数据库.

希望这会清除您的疑问.
如果您不同意我的意见,请回复您的建议.

问候,
Jitendra


我相信您已经知道答案了.编写查询的通常位置是在数据访问层中(这就是所谓的原因).在业务层中转换数据没有错,但是对实际需要的任何数据存储的实际访问都应该在DAL中完成.

这样做的原因很多,但以下是我最喜欢的几个:

1.您可以测试业务逻辑,而无需数据库访问.如果您有一个松散耦合的应用程序,那么将一个模拟对象放置到位以模拟您的数据访问就很简单.
2.如果您需要针对多个数据库供应商,那么您唯一需要更改的就是DAL(请注意,如果您使用的是nhybernate之类的ORM工具来合并数据模型,则DAL不适用). /blockquote>

IMO,数据访问层-但是其他人可能有自己的视图.


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

解决方案

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


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).


IMO, the Data access layer - however, others may have their own views.


这篇关于在哪里写查询更合乎逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆