linq查询中的问题 [英] Problem in linq query
本文介绍了linq查询中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我有以下实体
hello i have following entities
public class FileInformation : Entity
{
public string FileName { get; set; }
public string FilePath { get; set; }
public string Clientid { get; set; }
public List<ChangeInformation> ChangeInformations { get; set; }
public FileInformation()
{
this.ChangeInformations = new List<ChangeInformation>();
}
}
public class ChangeInformation
{
public string FileName { get; set; }
public string OldFileName { get; set; }
public long FileSize { get; set; }
public DateTime ModifiedDate { get; set; }
public string HashValue { get; set; }
public string DeviceID { get; set; }
public DateTime CreationDate { get; set; }
public string Status { get; set; }
public ChangeInformation()
{
}
}
i想要获取尚未删除的所有文件信息
什么我试过了:
i want to get all the fileinformation which have not been deleted
What I have tried:
var files = finfo.Where(n => n.ChangeInformations.Any(x=>x.Status !="Deleted");
推荐答案
您的代码将返回FileInformation
对象,如果它有任何ChangeInformation
对象,状态不是已删除。
现在,如果某个对象的状态已更改并删除,则会返回。我建议将其更改为:
这里,我们正在检查如果有任何状态被删除。如果是,不要接受它。
Your code will return theFileInformation
object if it has anyChangeInformation
object with status not as Deleted.
Now, if an object has statuses as changed and delete, it will be returned. I will recommend changing it to this:
Here, we are checking if any status is deleted. If yes, do not take it.
var files = finfo.Where(n => !n.ChangeInformations.Any(x=>x.Status == "Deleted");
如果删除总是在顶部, ChangeInformation
已排序日期的降序,如果状态被删除,您可以检查第一项。如果没有选择它。这样的事情:
If deleted is always going to be on top and ChangeInformation
is sorted in descending order of date, you can just check the first item if the status is deleted. If not select it. Something like this:
finfo.Where(x =>
(x.ChangeInformations != null && x.ChangeInformations.Count > 0 && x.ChangeInformations[0].Status != "Deleted")
);
这篇关于linq查询中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文