gpt4 book ai didi

asp.net-mvc - 我应该如何为需要在 ASP.NET MVC 中显示的分层数据构建我的 ViewModel?

转载 作者:行者123 更新时间:2023-12-04 13:28:40 25 4
gpt4 key购买 nike

我有一个看起来像这样的 View :

alt text

我试图弄清楚我应该如何为这个 View 表示我的 ViewModel。每个“机构”可以有多个“业务单位”,每个“业务单位”可以有多个“客户”。

在数据库中,我很容易地用一个映射表和代理、业务单位和客户表的外键来表示这一点。

但是,现在我需要使用 LINQ 从数据库中查询这些数据,然后构造一个表示这种树状结构的 ViewModel 对象,以便我的 View 可以呈现它。

谁能给我一些关于我应该使用什么数据结构的提示,或者我的 ViewModel 对于 C# 代码中的这个层次结构可能是什么样子?我需要创建我的 ViewModel 对象来传递给这个 View 。

任何关于如何表示 ViewModel 的建议表示赞赏!

最佳答案

只是在您的 View 数据中存储一个 List 实例?

public class Agency
{
public List<BusinessUnit> Units;
public string Name;
public int NumberOfAccounts
{
get
{
int ret = 0;
foreach(BusinessUnit unit in units)
ret += unit.NumberOfAccounts;
return ret;
}
}
// ... continue this strategy for other properties
}
public class BusinessUnit
{
public List<Client> clients;
public string Name;
public int NumberOfAccounts
{
get
{
int ret = 0;
foreach(Client client in clients)
ret += client.NumberOfAccounts;
return ret;
}
}
// ... continue this strategy for other properties

}
public class Client
{
public string Name;
public int NumberOfAccounts;
}

关于asp.net-mvc - 我应该如何为需要在 ASP.NET MVC 中显示的分层数据构建我的 ViewModel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1018679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com