净:如何创建独立于供应商的数据集,TableAdapter的,绑定(DB决定在运行时) [英] .Net: how to create vendor independent Dataset, Tableadapters, bindings (DB decided at runtime)

查看:218
本文介绍了净:如何创建独立于供应商的数据集,TableAdapter的,绑定(DB决定在运行时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#Windows窗体应用程序,它的原型SQL服务器(强类型数据集)上创建。在它的最终版本,应用程序必须能够工作过的SQL Server,MySQL或甲骨文。

现在我想知道哪些部分(如果有的话)可以从原型中重复使用。 1.数据集(类型)? 2. TableAdapter的? (可能不是,它们包含SQL Server特定的语法) 3.绑定到DataGridViews

最重要的是,如果我们需要重新实现这一切,有没有办法在设计时要做到这一点?要么, 1,我们需要以编程方式创建无类型,数据集? 2,我们需要以编程方式创建的数据适配器(或表适配器)?如果是的话,哪两个呢? 3,我们需要以编程方式创建其绑定到接口的datagridviews?

也许无关紧要:如果我们创建一个实体模型(AFAIK它提供DB独立)从现有的数据库架构,可我们用这个莫名其妙地创建绑定到我们的datagridviews

感谢您!

因此​​,为了保持我们的绑定和dataGridViews,以及我们已经实施了一些额外的逻辑,我们应该扔掉所有生成的TableAdapter和手动写出来?如果我们把它们扔掉,我们应该用DataAdapters呢?

这是一个由这本书的做法?有没有人做过这样的事?

更一般地,如果你需要创建一个窗体应用程序在多个DBS工作,你会怎么做:A与B.手工创建莫名其妙地产生一个独立于供应商的数据集类型化数据集,dataadapters /的TableAdapter和绑定和dataadapters / TableAdapter的通过VS鬼C.其他方式???(如何?),并结合他们在设计时

更新:

因此​​,为了保持我们的绑定和dataGridViews,以及我们已经实施了一些额外的逻辑,我们应该扔掉所有生成的TableAdapter和手动写出来?如果我们把它们扔掉,我们应该用DataAdapters呢?

这是一个由这本书的做法?有没有人做过这样的事?

更一般地,如果你需要创建一个窗体应用程序在多个DBS工作,你会怎么做:A与B.手工创建莫名其妙地产生一个独立于供应商的数据集类型化数据集,dataadapters /的TableAdapter和绑定和dataadapters / TableAdapter的通过VS鬼C.其他方式???(如何?),并结合他们在设计时

解决方案
  1. 的类型化的DataSet /表是数据库无关。 (但是,如果你在设计中添加适配器他们得到DB-具体。不要从设计师使用适配器
  2. 的适配器数据库无关。
  3. 在数据绑定数据库无关。的拖放数据绑定但要注意自动添加适配器


我的建议是:

  • 从数据集中删除adpaters 设计师
  • 重写用一个简单的类自己的资料库/适配器与get方法/填充 表。所以,你使用,而不是生成的适配器他们。这些类可以是DB-具体。因此,例如一个PersonRepositorySqlServer,PersonRepositoryMySql。或者,也许你给DB型与构造重用SQL尽可能..
  • 如果您使用的适配器上的形式, 他们转移到。 c中的填充手 - $ C $ 该数据集的

我总是这样回答的问题,其余

  • 在我使用的类型化数据集,但我只是做表,而不是适配器
  • 在我Usualy c中的数据绑定$ C $因为有时设计师弄乱了,但是这是没有必要为分贝独立
  • 在我写使用适配器来填充/获取/更新的数据表我自己的信息库。然而 我code他们的手。给定一个类型化的DataTable这是相当容易auomatically生成更新/插入/删除/的方式填写报表。



重写适配器看起来很难,但实际上是pretty的可行。

I have a C# Windows Forms application, whose prototype was created on SQL Server (strongly-typed dataset). In its final version, the application must be able to work over SQL Server, MySQL or Oracle.

Now I am wondering which parts (if any) can be reused from the prototype. 1. Dataset (typed) ? 2. TableAdapters? (probably not, they contain SQL Server-specific syntax) 3. Bindings to DataGridViews

Most importantly, if we need to re-implement all this, is there a way to do this at design-time? Or, 1. do we need to programmatically create untyped-dataset? 2. do we need to programmatically create its data adapters (or table adapters)? If yes, which of the two? 3. do we need to programmatically create its bindings to the datagridviews of the interface?

Perhaps irrelevant: if we create a entity model (AFAIK it provides db independence) from the existing db schema, could we use this somehow to create bindings to our datagridviews?

Thank you!

So, in order to keep our Bindings and dataGridViews, as well as some additional logic we have implemented, should we throw away all the generated TableAdapters and write them manually? If we do throw them away, should we use DataAdapters instead?

Is this a "by-the-book" approach? Has anyone done something like this?

More generally, if you need to create a Forms application to work in multiple dbs, would you do it: A. with untyped dataset, dataadapters/tableadapters and bindings created by hand B. somehow generate a vendor-independent dataset and dataadapters/tableadapters (how?) and bind them at design time through the VS gui C. some other way???

UPDATE:

So, in order to keep our Bindings and dataGridViews, as well as some additional logic we have implemented, should we throw away all the generated TableAdapters and write them manually? If we do throw them away, should we use DataAdapters instead?

Is this a "by-the-book" approach? Has anyone done something like this?

More generally, if you need to create a Forms application to work in multiple dbs, would you do it: A. with untyped dataset, dataadapters/tableadapters and bindings created by hand B. somehow generate a vendor-independent dataset and dataadapters/tableadapters (how?) and bind them at design time through the VS gui C. some other way???

解决方案

  1. The typed dataset/table is database independent. (however, if you add adapters in the designer they get DB-specific.. Don't use adapters from the designer
  2. The adapters ARE NOT database independent.
  3. Databinding is database independent. But beware of drag-drop databinding automatically adding an adapter


My advice:

  • Remove the adpaters from the dataset designer
  • Rewrite your own repositories/adapters using a simple class with methods that get/fill tables. So you use them instead of the generated adapters. These classes can be DB-specific. So for instance a PersonRepositorySqlServer,PersonRepositoryMySql. Or perhaps you give the db-type with the constructor to reuse the SQL as much as possible..
  • If you used adapter on your forms, remove them to. Hand-code the filling of the dataset

What I always do to answer the rest of the questions

  • I use typed datasets but I just make the tables and not the adapters
  • I Usualy code the databindings since sometimes the designer messes up but this is not necessary to be db independent
  • I write my own repositories that use adapters to fill/get/update the datatables. However I code them by hand. Given a typed datatable it's rather easy to auomatically generate update/insert/delete/fill statements by the way..



Rewriting the adapters looks hard but is actually pretty doable.

这篇关于净:如何创建独立于供应商的数据集,TableAdapter的,绑定(DB决定在运行时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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