在c#中通过linq查询查找记录 [英] Find a record through linq query in c#
本文介绍了在c#中通过linq查询查找记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,这些是我的实体
Dear friend these are my 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()
{
}
}
< br $> b $ b
如何找到所有删除了更改信息状态的文件?
什么我试过了:
i试过以下查询
var files = finfo.Where(n => n.ChangeInformations .Where(x => x.Status ==Deleted);
how i can find all the files whose status in change information are deleted ?
What I have tried:
i have tried following query
var files = finfo.Where(n => n.ChangeInformations.Where(x=>x.Status=="Deleted");
推荐答案
Where子句是Func< tinput,bool>
。这意味着返回必须是布尔值。n.ChangeInformations.Where(x => x.Status ==Deleted)
如果任何项符合条件,则应使用Any返回布尔值:
A Where clause isFunc<tinput,bool>
. That means that the return must be a boolean.n.ChangeInformations.Where(x=>x.Status=="Deleted")
is not a boolean. You should use Any which will return a boolean if any items match the criteria:
var files = finfo.Where(n => n.ChangeInformations.Any(x=>x.Status=="Deleted"));
这个地方告诉你这是怎么做的
C#中的101个LINQ样本 [ ^ ]
This place show you how do this
101 LINQ Samples in C#[^]
这篇关于在c#中通过linq查询查找记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文