数据库查询的多态 [英] Polymorphism with Database Query

查看:161
本文介绍了数据库查询的多态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个显示企业指标的仪表板(目前在C#中使用ASP.net 3.5),并寻求设计意见。我在网络应用程序中不太习惯OOP。



在多对多关系中,不同的用户可能会看到许多不同的指标。我正在将用户存储在本地SQL数据库中,当然也可以为每个Metric存储元数据。这也为每个访问控制列表提供了一种。每个指标可以有几个不同的图表,它们具有不同的设计(不同的y轴上的不同系列的条形,列,馅饼,线条或组合等)。



这些图表可以以编程方式设计,然后在运行时添加到ASP.net页面。拥有一个空白图表的超类的继承结构和不同图表类型的继承结构将是很好的。



该页面将选择给定用户具有的图表权利查看然后生成那些。然而,我看到一些大的switch语句是一个粗略的查找表,用于根据数据库中选择的信息来实例化相应的子类。



有没有更艺术的做法吗不知何故在运行时提供类型声明?我应该将所有关于图表的样式信息移动到数据库中,并为数组,数据点,颜色等添加其他表和列,其中单个图表类执行所有必需的查询并构建图表?谢谢。

解决方案

我意识到我正在寻找的可以用动态类加载来解决。
C#中有一个动态类加载的例子这里



基本上我可以根据查询中的字符串文件名加载一个类。


I am designing a dashboard to display corporate metrics (currently with ASP.net 3.5 in C#), and looking for advice on design. I'm not as used to OOP in web applications.

There may be many different metrics that can be seen by different users in a Many-to-Many relationship. I am storing the users in a local SQL database and it of course makes sense to store the metadata for each "Metric" as well. This also provides a sort of access control list for each one. Each metric can have several different charts which have different designs (bars, columns, pies, lines, or combinations of those with different series on different y-axes, etc...).

These charts could be designed programmatically and then added to the ASP.net page at runtime. It would be nice to have an inheritance structure of a superclass of a blank chart and different chart types that extend that.

The page would select the charts the given user has the right to view and then generate those. Still, I'm seeing some kind of big switch statement as a crude lookup table for the appropriate subclass to instantiate based on the information selected in the database.

Is there a more artistic way to do this? Somehow supplying the type declaration at runtime? Should I move all the style information about the charts into the database and have additional tables and columns for series, datapoints, colors, etc, where a single chart class does all the necessary queries and builds a chart? Thanks.

解决方案

I realized what I'm looking for could be solved with dynamic class loading. There's a great example of dynamic class loading in C# here from Michael Clarke.

Basically I can load a class based on a string filename coming from a query.

这篇关于数据库查询的多态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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