SqlDataSource的VS ObjectDataSource控件 [英] SqlDataSource vs ObjectDataSource

查看:100
本文介绍了SqlDataSource的VS ObjectDataSource控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个网页需要一些数据,为什么不只是有一个SqlDataSource调用存储过程?为什么要使用一个ObjectDataSource调用的业务对象,然后调用存储过程?据我所知,其他应用程序(可以说桌面应用程序),建立在.NET框架可以访问业务对象,但是如果应用程序将永远只有一个web应用程序?

If a web page needs some data, why not just have a SQLDataSource call a stored procedure? Why use an ObjectDataSource to call a business object that then calls the stored procedure? I understand that other apps (lets say desktop apps) built on the .net framework can access the business objects, but what if the application will always be only a web app?

要得到更清晰的:

当一个人应该使用的SqlDataSource ObjectDataSource控件

怎样才能激发的选择?

推荐答案

刚刚一个SqlDataSource是完全有效的,如果它只是一个演示,原型,或快速破解。它速度快,很容易,它只是工作,并为您提供您所需要的结果。

Having just a SQLDataSource is perfectly valid, if it's just a demo, a prototype, or a quick hack. It's fast, it's easy, it just works and gives you the results you need.

然而,当一个应用程序的设计和建造从长远来看,和预计的事情(需求,客户的意愿,最终的数据库模式)可能会改变,那么它可能做了一大堆更多的意义,介绍一个合适的业务图层 - 建模业务对象为对象,然后提供这些业务对象从基础数据库的映射

However, when an app is designed and built for the long run, and anticipates that things (requirements, customer wishes, eventually the database schema) may change, then it might make a whole lot more sense to introduce a proper "business" layer - model your business objects as objects, and then provide a mapping from the underlying database to those business objects.

俗话说 - 你可以在计算机科学中一个更间接层(或抽象)的解决pretty的多的东西 - 同样适用此

As the saying goes - you can solve pretty much anything in computer science by one more layer of indirection (or abstraction) - same holds here.

肯定的:你可以直接进入数据库,并肯定的是,在第一,对于第一次迭代,这可能是(或可能)的最快方法。但是,从长远来看,当一个应用程序被内置到最后,它通常是一个单触和肮脏办法 - 维护的成本,维护费用,需要根据不断变化的成本和精力你和你的客户的需求将增长,并很快,这quick'n'dirty的解决方案看起来不那么大了,在精力方面。

SURE: you can go straight to the database, and sure, at first and for the first iteration, that's possibly (or probably) the quickest way. But in the long run, when an app is built to last, it's usually a quick-and-dirty way - the cost of upkeep, the cost of maintenance, the cost and effort needed for changing according to your and your customer's needs will grow and quite quickly, that quick'n'dirty solution doesn't look so great anymore, in terms of effort.

所以,总结一下我的观点:是的,一开始,使用直接的SQL数据源可能会更快和更容易 - 所以使用它时,这是很重要的一点:把事情的快速演示完成后,一个证明型概念风格的应用程序。但是从长远来看,当你看到一个应用程序的生命周期,它通常是值得的投资多一点(设计和编码)努力增加这个抽象层,使你的网页不直接依赖于细节下方的数据库

So to sum up my point: yes, initially, using a direct SQL Data source might be quicker and easier - so use it when that's the important point: to get things done for a quick demo, a proof-of-concept style app. But in the long run, when you look at the life span of an app, it's usually worthwhile investing a bit more (design and coding) effort to add this layer of abstraction so that your web pages don't directly depend on the details of the database underneath.

马克·

这篇关于SqlDataSource的VS ObjectDataSource控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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