【发布时间】:2023-02-14 11:15:19
【问题描述】:
抱歉,这将是一个很长的问题。但有必要阐明其中的逻辑。
该实体具有数据库中的所有列:
public partial class Institution
{
public int? Id { get; set; }
public string? District { get; set; }
public string? InstitutionCode { get; set; }
public string? InstitutionName { get; set; }
public string? DemolitionStatus { get; set; }
public string? ReinforcementStatus { get; set; }
public string? BuildingOwnerStatus { get; set; }
public string? BuildingOwnerInstitution { get; set; }
public string? ClosureStatus { get; set; }
public string? ActivityStatus { get; set; }
public string? ETStatus { get; set; }
public int? ETPhase1 { get; set; }
public int? ETPhase2 { get; set; }
public int? ETPhase3 { get; set; }
public string? InfrastructureStatus { get; set; }
public string? InfrastructureScope { get; set; }
public string? InfrastructureInfo { get; set; }
public string? InfrastructureScopeOut { get; set; }
public string? IAccessStatus { get; set; }
public string? IAccessType { get; set; }
public string? ComputerClassStatus { get; set; }
public int? ComputerClassNumber { get; set; }
public int? PCNumber { get; set; }
public string? ComputerClassScope { get; set; }
public int? ETNeed { get; set; }
}
我已经为包含 ET 的列定义了一个模型,因此不会处理所有列,因为我将只显示与 ET 相关的用户数据。
public class ETModel
{
public int? Id { get; set; }
public string? District { get; set; }
public string? InstitutionCode { get; set; }
public string? InstitutionName { get; set; }
public string? ActivityStatus { get; set; }
public string? ETStatus { get; set; }
public int? ETPhase1 { get; set; }
public int? ETPhase2 { get; set; }
public int? ETPhase3 { get; set; }
public int? ETNeed { get; set; }
}
然后,我定义了一个包含列表类型成员的视图模型,因为我将向用户返回两个列表。我将此视图模型编辑为 ETmodel。
public class ETListVM
{
public List<ETModel> ETyes { get; set; }
public List<ETModel> ETnone { get; set;}
}
我在控制器中实例化了视图模型。我定义了两个列表类型的变量。但我无法填写这些列表。我可以用 Institutions 实体填充它,但这次我偏离了我的目的。我正在使用所有列。我的目标是使用 ETModel 使用更少的资源。
public IActionResult Index(string district)
{
ETListVM vm= new ETListVM();
var ETyesList = c.**XXX**
.Where(p => p.District == district && p.ETStatus == "yes")
.ToList();
var ETnoneList = c.**XXX**
.Where(p => p.District == district && p.ETStatus == "none")
.ToList();
vm.ETyes = ETyesList;
vm.ETnone = ETnoneList;
return View();
}
如果我将 Institutions 实体写在我指定的位置XXX,它有效,但它不接受我想使用的 ETModel。感谢您的耐心等待和帮助。
注意:它只有在我定义一个具有相关属性的新实体时才有效,但此时 ETModel 变得毫无意义。
【问题讨论】: