最佳“当前”用于松散耦合不断变化的代码的 MS 数据访问技术?

发布于 2024-11-24 19:11:20 字数 403 浏览 1 评论 0原文

我在我的项目中做了很多非类型化数据集工作,并且已经这样做了一段时间,但是当使用 datagridview 的就地编辑时,我发现如果使用类型化数据集,验证和其他东西会容易得多。

但这提出了一个问题,因为我不喜欢使用这些数据集设计器来创建强类型数据表/数据集。与非类型化数据集相比,类型化数据集以后更难进行简单的更改。类型化数据集更改需要安装 VS 的副本,而非类型化数据集则不需要。我可以更改数据库服务器上的 sql 视图,应用程序将在我的网格中显示新列。他们可能无法使用新列,但我的大部分内容都是信息显示,所以没关系。

我查看了实体框架,但看起来也必须运行一些向导来构建数据模型。我并不反对数据模型,但如果它能在运行时生成,这样对数据库的新更改不需要软件重新编译,那就太好了。

有快乐的媒介吗?或者我是否在启动时创建非类型化数据表的时间更长了?

I do a lot of untyped dataset work in my projects and have done so for a while but when working with in-place editing of datagridview I found it's a lot easier for validation and stuff if you use a Typed Dataset.

This poses an issue though because I don't like using those dataset designers to create strongly typed datatables/datasets. It makes it harder to make simple changes down the road when the dataset is typed than it does with untyped. Typed dataset changes require a copy of VS to be installed whereas untyped doesn't. I can change a sql view on the db server and the apps will show the new column in my grid. They may not be able to use the new column but most of my stuff is info display so that's ok.

I looked at Entity Framework, but it too looks like a few wizards must run to build your data model. I'm not against a data model but it would be great if it would generate at runtime so that new changes to the db don't require software recompiling.

Is there a happy medium? Or am I stuck creating untyped datatables at startup for a while longer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

全部不再 2024-12-01 19:11:20

当然,这只是品味问题,但我发现数据集是万恶之源
好吧,也许不是全部都是邪恶的,但它们代表了一种没有与之相关的行为的数据结构 =>它们不是对象(如 OOP 中定义的)=>使用它们可以促进非 OOP 风格的编程(更不用说过程式编程了)。

其他一些要点:

  1. gridviews 和任何其他控件完全支持绑定到对象列表(而不仅仅是数据集)。
  2. 我认为,如果您必须更改数据模型,安装 VS 的副本并不算过分的要求。
  3. 同样,当您更改数据模型时,必须重新编译代码也不是夸张的要求。
  4. 如果,当您更改数据库中的表时,这会强制更改您的用户界面,我会说它不是任何想象的“松散耦合”。

我相信使用数据集的唯一理由是将数据从数据库中提取出来,然后将其传输到您的对象中。
但现在,如您所知,如果没有必要,您可以使用 ORM 来完成这项工作(EF 是其中之一,nHibernate 是另一个更好的选择)。

因此,总而言之,我强烈建议您重新考虑数据集的使用,因为它们违背了面向对象的基础知识。

附:
抱歉,如果这听起来有点情绪化——我是根据痛苦的个人经历说的。
我为此烦恼了两年,因为我正在开发的应用程序到处都使用了数据集,这意味着我们也必须重复所有数据的行为。呃……

It's all a matter of taste, of course, but I find that Datasets are the root of all evil.
well, maybe not all evil, but they represent a data structure that has no behavior associated with it => they are not objects (as defined in OOP) => using them promotes non-OOP style programming (not to mention procedural programming).

some other points:

  1. gridviews and any other control fully support binding to a list of objects (and not just datasets).
  2. I think that, if you have to make changes to your data model, having a copy of VS installed is not too much to ask.
  3. along the same lines- it's also not an exaggerated requirement to have to recompile your code when you make changes to your data model.
  4. if, when you change a table in your db, that forces a change on your UI, I would say it's not "loosely coupled" by any stretch of the imagination.

I believe that the only justification for using datasets is to pull data out of your db and then transfer it into your objects.
but now, as you know, if that isn't necessary- you have ORMs that do that job for you (EF is one, nHibernate is another, better, option).

so, in conclusion- I strongly recommend you reconsider your use of DataSets, as they go against the very basics of Object-Oriented.

p.s.
sorry if this came across as a little emotional- I was talking from bitter personal experience.
I was pulling my hair out for 2 years because the app I was working on had used DataSets all over, and that meant that we had to duplicate the behavior for that data all over as well. uughh....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文