获取计数通过获取linq查询获取正确的数据 [英] Get Count with get proper data by getting linq query
本文介绍了获取计数通过获取linq查询获取正确的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一些小应用程序,我希望从linq查询获取数据,我使用
I have develop some small application, which in i want to get data from linq query which in I have bind using
public List<FileDescription> lstFile = new List<FileDescription>();
型号。
和在这里,是一个获取我想要的所有数据的linq查询。
model.
and here, is one linq query which getting all data which I want.
var lstFileDesc = (from p in appConDesc.lstFile where p.FileID == FileID select p);
if (lstFileDesc.Count() >= 1)
{
fileName = lstFileDesc.Single().FileName;
fileType = lstFileDesc.Single().FileType;
}
上面,在lstFileDesc变量中,我得到了所有来自linq查询的数据,但是如果条件是未插入,意味着数据采用不同的方法。
谢谢,
Above, In lstFileDesc variable i get all data which is getting from linq query, but in if condition they are not inserted,means that data are getting to different method.
Thanks,
推荐答案
不确定我理解你好,但是......你可能只想获得FileName
和FileType
结果而不是p
对象的所有属性。
Not sure i understand you well, but... you probably want to get onlyFileName
andFileType
as an result instead of all properties ofp
object.
var lstFileDesc = appConDesc.lstFile
.Where(p=>p.FileID==FileID)
.Select(p=>new{FileName = p.FileName, FileType = p.FileType});
这篇关于获取计数通过获取linq查询获取正确的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文