最佳“当前”用于松散耦合不断变化的代码的 MS 数据访问技术?
我在我的项目中做了很多非类型化数据集工作,并且已经这样做了一段时间,但是当使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,这只是品味问题,但我发现数据集是万恶之源。
好吧,也许不是全部都是邪恶的,但它们代表了一种没有与之相关的行为的数据结构 =>它们不是对象(如 OOP 中定义的)=>使用它们可以促进非 OOP 风格的编程(更不用说过程式编程了)。
其他一些要点:
我相信使用数据集的唯一理由是将数据从数据库中提取出来,然后将其传输到您的对象中。
但现在,如您所知,如果没有必要,您可以使用 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:
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....