如何查询包含多个列表的对象列表

本文关键字:列表 对象 包含多 何查询 查询 | 更新日期: 2023-09-27 18:11:34

我有一份病人名单。每个病人都有几个单子:

public class Patient
{
    private List<DateTime> serverTimeStamps;
    protected List<int> sessionStages;
    protected List<string> revIPage;
    protected List<double> current;
    protected List<int> n_ok;
    protected List<int> n_LE;
}

患者列表称为ptLsit,我试图获得serverTimeStamp大于_initTimeToAskData的列表项(来自所有列表,而不仅仅是serverTimeStamps)。我能给出的最好的例子是

ptLsit.Where(x=> x.ServerTimeStamps.Select(ts => ts >= _initTimeToAskData))

如何查询包含多个列表的对象列表

基于这个类:

public class Patient
{
    public List<DateTime> serverTimeStamps;
    public List<int> sessionStages;
    public List<string> revIPage;
    public List<double> current;
    public List<int> n_ok;
    public List<int> n_LE;
}

Try this:

var result = ptLsit.Where(p => p.serverTimeStamps.Any(d => d > _initTimeToAskData))
    .Select(p => new Patient{
        serverTimeStamps = p.Where(x => x > DateTime.Now).ToList(),
        // Fill the other properties...
        // ...
        });

您将获得至少包含大于参数_initTimeToAskData的DateTime的Patient列表,并且结果对象将在serverTimeStamps属性

中包含正确的日期