从 LINQ 查询结果返回单个属性
以下表达式返回一个联系人 - 具有数十个属性的整个联系人。这很好,但理想情况下,我希望返回的只是联系人的 id (contact.contactId) 属性。我该怎么做?
var assocOrg = Contacts.Where(x => x.ContactTypeID == 2 && x.OrganizationName == "COMPANY XYZ");
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");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
或者
or
如果您想获得符合您条件的单个或第一个对象,请使用以下命令:
If you want to get a single or first object matching your conditions , use this :
这将为您提供第一个 ContactId,接下来将为您提供
Sql 样式的 ContactId 列表,该列表为
That would get you the first ContactId and the following would get you a list of ContactId's
In Sql style that would be