【问题标题】:What i need to Change here in my List<> on employee object我需要在员工对象的列表<>中更改
【发布时间】:2018-11-07 13:47:34
【问题描述】:

这是我的员工对象

      public class Employee : BaseEntity
{        
    public Employee()
    {
        this.HistoryOfStatuses = new List<Checkinout>();
    }
    public string Name { get; set; }
    public string Department { get; set; }
    public string CardNumber { get; set; }
    public string Status { get; set; }
    public Checkinout ActualCheckinStatuse { get; set; }
    public List<Checkinout> HistoryOfStatuses { get; set; }
    public int UserId { get; internal set; }
    //test
}

}

这是我的控制器

   HistoryOfStatuses = (from checkinout in context.Checkinout
                        join status in context.Status on checkinout.CheckType equals status.Statusid
                        where checkinout.Userid == userinfo.Userid
                        orderby checkinout.CheckTime descending
                        select new Checkinout
                        {
                            CheckStatus = status.StatusText,
                            CheckTime = checkinout.CheckTime
                         }).ToList()

这是我的 Checkinout 课程

     public class Checkinout: BaseEntity
{
   public Checkinout() {
    }
    public int EmployeeId { get; set; }
    public string CheckStatus { get; set; }
   public DateTime CheckTime { get; set; }
   public Employee EmployeeObject { get; set; }

}

这是我的观点,我不能使用 CheckStatus 或 CheckTime

This is my view

【问题讨论】:

  • 请在您的屏幕截图中包含该错误消息,作为您问题的一部分,而不是在链接中
  • 包含 Checkinout 类的代码

标签: c# linq .net-core


【解决方案1】:

据我所知,您的 HistoryOfStatuses 是一个列表,因此您不应该调用列表的属性,您应该首先对列表进行迭代,然后访问当前迭代对象的属性。

所以你可能需要做一个 foreach 循环。例如:

@foreach(var history in item.HistoryOfStatuses){
    <h1>@history.CheckStatus</h1>
}

【讨论】:

  • 这就是我所需要的,谢谢你。
【解决方案2】:

HistoryOfStatuses 是一个List,它没有CheckStatus 的属性。

在使用CheckStatus 属性之前,您需要从列表中选择一个项目。

类似的,

item.HistoryOfStatuses[0].CheckStatus

这是假设您想要列表中的第一条记录,这可能不是您想要的。但关键是您需要从列表中选择一个项目或循环遍历列表。

【讨论】:

    猜你喜欢
    • 2011-05-08
    • 2020-09-19
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 1970-01-01
    • 2023-02-09
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多