.NET数据集与业务对象:为什么辩论?为什么不结合这两个? [英] .NET Dataset vs Business Object : Why the debate? Why not combine the two?

查看:143
本文介绍了.NET数据集与业务对象:为什么辩论?为什么不结合这两个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在评论中阅读了一个辩论 here 当前活的网站,没有评论)。



为什么辩论?对我来说,数据集就像一个关系数据库,一个Object是一个层次结构的模型。为什么人们绝对需要一个纯粹的对象模型,而我们仍然处理关系数据库,所以为什么不组合这两个?



如果我们应该有轻量级,全面的框架,使我们能够做到这一点(不是一个沉重的猛mamm象,像NHibernate,它有一个巨大的学习曲线)?

解决方案

p>纯对象更容易使用,类型化对象可以给您进行智能感知和编译时类型检查。



裸数据集非常繁琐而烦人使用 - 你需要知道列名,没有类型检查可能,所以如果你输入一个列名称,你没有运气,直到运行时才会发现错误(最糟糕的情况)。



类型数据集是朝着正确方向迈出的一步,但您在.NET代码中处理的事情仍然非常紧密地与您的数据库实现相关联 - 通常不会好事,因为任何一个chan基础数据库中的ge可能会影响到您的应用程序,直到您的UI,并导致需要进行大量更改。



使用像NHibernate这样的ORM,可以更好地抽象并将数据库(物理存储)层与您的逻辑业务模型分离 - 只有在最简单的情况下,这两个方法才是1:1匹配,所以您需要一些翻译或两者之间的映射。所以所有这一切 - 使用类型化的数据集对于小而简单的应用来说可能是可以的,但对于一个富有挑战性的,规模更大的企业级商业应用,我永远不会建议将您的业务对象模型与数据库紧密相连。



Marc


I read a debate in the comments here (current live site, without comments).

Why the debate? A Dataset for me is like a relational database, an Object is a hierarchical-like model. Why do people absolutely want a "pure" Object model, whereas we still deal with relational databases, so why not combine the two?

And if we should, is there any lightweight, comprehensive framework that allows us to do that (not a heavy mammoth, like NHibernate, which has a huge learning curve)?

解决方案

"Pure objects" are a lot easier to work with, the typed object gives you intellisense and compile-time type checking.

Bare datasets are very cumbersome and annoying to work with - you need to know the column names, there's no type checking possible, so if you mistype a column name, you're out of luck and won't discover the error until runtime (the worst possible scenario).

Typed datasets are a step in the right direction, but the "things" you work with in your .NET code are still tied very closely and tightly to your database implementation - not typically a good thing, since any change in the underlying database might affect your app all the way up to your UI and cause a lot of changes being necessary.

Using an ORM like NHibernate allows you to better abstract and decouple the database (physical storage) layer from your logical business model - only in the simplest of scenarios will those two be an exact 1:1 match, so you'll need some kind of "translation" or mapping between the two anyway.

So all in all - using typed datasets might be okay for small, simple apps, but for a challenging, larger-scale, enterprise-level business app, I would never recommend coupling your business object model so closely and tightly to the database.

Marc

这篇关于.NET数据集与业务对象:为什么辩论?为什么不结合这两个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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