.NET 数据集与业务对象:为什么要争论?为什么不将两者结合起来? [英] .NET Dataset vs Business Object : Why the debate? Why not combine the two?

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

问题描述

我在评论中读到了一场辩论 这里 (当前直播网站,无评论).

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?

如果我们应该这样做,是否有任何轻量级、全面的框架可以让我们做到这一点(而不是像 NHibernate 这样具有巨大学习曲线的笨重的庞然大物)?

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

类型化数据集是朝着正确方向迈出的一步,但是您在 .NET 代码中使用的事物"仍然与您的数据库实现非常紧密地联系在一起——这通常不是一件好事,因为底层的任何变化数据库可能会影响您的应用程序直至您的 UI,并导致需要进行大量更改.

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.

使用像 NHibernate 这样的 ORM 可以让您更好地将数据库(物理存储)层与您的逻辑业务模型进行抽象和解耦 - 只有在最简单的场景中,这两者才能精确地 1:1 匹配,因此您需要无论如何,两者之间存在某种翻译"或映射.

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.

马克

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

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