问题描述
我必须编写一个复杂的查询,以获取我们系统中针对我们在数据库中的每个代理机构的规则的一些统计信息。
I have to write kind of a complicated query to get some statistics for the rules in our system for each Agency we have in our database.
它看起来像这个:
此数据将会有任意数量的列(规则)和行(代理机构)。例如,这里显示了5条主要的规则列,但这可以很容易地是1或2列。每列包含3个数字(标记,百分比和天数)。我甚至不能让我的大脑是数据结构应该从我的数据库返回到代表这个?
There will be an arbitrary number of columns (rules) and rows (agencies) for this data. For example, here there are 5 main rule columns shown, but this could just as easily be 1 or 2 columns instead. Each column consists of 3 numbers (Flagged, Percent and Days). What I can't even get my brain around is what datastructure should I even return from my database to represent this?
最终我需要构建一个看起来像这样的东西我的ASP.NET MVC视图,但是现在我只是试图从数据库中获取数据并将其表示在一个逻辑数据结构中,在构建表时很容易使用。
Eventually I need to construct something that looks like this in my ASP.NET MVC view, but right now I'm just trying to get the data out of the database and represent it in a logical datastructure that will be easy to work with when constructing this table.
我应该使用什么数据结构来表示任意数量的列/行的表格数据?如果你不得不将这个数据从LINQ查询中返回数据库,那么你会把它放在什么样的容器里?
What data structure should I use to represent my tabular data with an arbitrary number of columns/rows? If you had to return this data out of the database in a LINQ query, what kind of container would you put it in?
推荐答案
不确定LINQ:
但是以面向对象的方式表示它们是直接的。
But to represent them in Object Oriented fashion is straight-forward.
代理 - > n规则 - >每个规则都有属性
Agency -> n-Rules -> Each Rule has attributes
EgRule对象将包含:
E.g.Rule Object will consist of:
class Rule { //Probably you would like to call something more business related
String ruleName; //E.g. Duplicate Accounts at Same Agency
int numberOfFlagged; //E.g 4
int percent; //E.g. 1%
int days; //E.g. 6
}
class Agency {
List<Rule> rules;
}
加载数据后,您将在Excel或视图中表示您想要的。
Once you have the data loaded you represent in Excel or a View as you want.
这篇关于您将用什么数据结构来表示这种格式的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!