C# (WPF):数据库关系查看器
我想用 C# 创建一个 WPF 应用程序,它可以以用户界面友好的方式直观地显示从应用程序用户(MS SQL Server、MS Access、Oracle、MySQL 等)并允许编辑关系。
例如,在 Microsoft Access 2007 中,可以通过至少有 2 个表并单击数据库工具选项卡,然后单击关系。另一个例子是在 Microsoft SQL Server 中创建数据库图表时。
第一步是创建一个数据访问层以允许连接到不同类型的数据库(取决于提供程序类型)。
我不知道 .NET 中是否已经有某种查看器(或者可能是免费的第三方库)可以做到这一点。你认识一个吗?如果不是,使用 WPF 手动执行此操作的主要步骤是什么?
感谢您的任何帮助和建议!
I would like to create a WPF application in C# that can show visually, in a user interface friendly way, the relationships between tables from a database chosen from the application user (MS SQL Server, MS Access, Oracle, MySQL, etc.) and allow the editing of the relationships.
For example, in Microsoft Access 2007 it is possible to do such a thing by having at least 2 tables and clicking on the Database Tools tab and then on Relationships. Another example is in Microsoft SQL Server when creating a diagram of the database.
The first step would be to create a data access layer to allow the connection to different types of databases (depending on the provider type).
I am not aware if there is already some sort of viewer in .NET (or maybe a free third party library) that could do the trick. Do you know one? If not what are the big lines for doing it manually with WPF?
Thank you for any help and suggestions!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您也许可以查看 MS Access 2007 的 MS Office PIA,看看是否可以找到您正在谈论的查看器...
You could maybe have a look at the MS Office PIAs for MS Access 2007 and see if you can find the viewer you are talking about...
这里有很多“大门票”项目,但我们将从核心功能开始。
数据库任务:
枚举表
对于每个表 - 枚举关系。
为您希望处理的每种数据库类型抽象上述功能。
用户界面任务:
布置桌子(简单的相同尺寸的盒子)
为每个关系画线
实施拖放放置 - 在放置时重绘关系线。
现在,这并不能处理漂亮的曲线,也不能很好地路由这些线
它也不处理表格列,因此 UI 中的所有表格“框”大小相同,从而简化了布局。
但这种级别的功能作为概念证明是一个很好的目标。
如果这是针对专业客户的,请不要在上面浪费时间。
但是,如果是为了学习经验,那就去吧!从这样的项目中可以获得很多有价值的东西,您将在您的编程生涯中一次又一次地使用它们。
希望这有帮助!
There's a good number of 'Big Ticket' items here, but we'll start from the core functionality.
DB Tasks:
Enumerating the Tables
For each table- enumerate relationships.
Abstract above functionality for each DB type you wish to deal with.
UI Tasks:
Lay out tables (simple same size boxes)
draw lines for each relationship
Implement Drag & Drop - redraw relationship lines on drop.
Now, this doesn't deal with nice curved lines, and routing those lines nicely
It also doesn't deal with the table columns, so all the table 'boxes' in the UI are the same size, which simplifies layout.
But this level of functionality is a good goal as a proof of concept.
If this is for a client, in a professional capacity, dont waste your time on it.
However if it is for the learning experience then go for it! There's lots of nice nuggets to be gained from a project like this that you will use again and again in your programming career.
hope this helps!
读取外键关系可能并不简单。我的申请包括以下评论:
Reading the foreign key relationships may be non-trivial. My application includes the following comment:
它不是免费的,但对于任何 WPF 图表,我总是使用 Mindscape 的图表产品 WPF 流程图。该产品很棒,支持也很棒。
It's not free, but for any WPF diagramming I would always use Mindscape's diagramming product WPF Flow Diagrams. The product is great and the support is superb.
Visual Studio 中内置了此类查看器,请转到“工具”->“工具”->“工具”->“工具”。连接到数据库,并将其全部连接到数据库。然后,当您在服务器资源管理器上看到数据库时,打开一个表并查看工具栏中的不同按钮,其中一个按钮会将表显示为灰色背景上的小窗口。打开该窗口后,您可以将其他表拖/放到灰色区域中,它将显示所有关系。
There is a viewer of this sort built into visual studio, go to Tools-> Connect to Database, and get it all hooked up to the database. Then when you see the database on the Server Explorer, open a table and look at the different buttons in your toolbar, there's one that will bring the table up as a little window on a grey background. Once you've got that window open, you can drag/drop other tables into the gray area and it will show you all there relationships.