从LINQ查询结果返回单个属性 [英] Returning a single property from a LINQ query result
本文介绍了从LINQ查询结果返回单个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面EX pression返回一个接触 - 几十个属性的整个接触。这是好的,但是,理想情况下,我想回报是联系人的ID(contact.contactId)唯一的财产。如何做到这一点?
VAR assocOrg = Contacts.Where(X => x.ContactTypeID == 2及和放大器; x.OrganizationName ==XYZ公司);
解决方案
VAR的结果= Contacts.Where(X => ...)
。选择(X => x.ContactID);
或
VAR的结果=从X通讯录
其中x.ContactTypeID == 2&安培;&安培; x.OrganizationName ==XYZ公司
选择x.ContactID;
The following expression returns a contact - the whole contact with dozens of properties. This is fine but, ideally, I'd like the return to be the contact's id (contact.contactId) property only. How do I do this?
var assocOrg = Contacts.Where(x => x.ContactTypeID == 2 && x.OrganizationName == "COMPANY XYZ");
解决方案
var result = Contacts.Where(x => ...)
.Select(x => x.ContactID);
or
var result = from x in Contacts
where x.ContactTypeID == 2 && x.OrganizationName == "COMPANY XYZ"
select x.ContactID;
这篇关于从LINQ查询结果返回单个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文