我有兩個列表,我必須從中獲取兩個值(MyCaption和MyValue)。在查詢中的Linq子查詢
List<UserInfoModel> userInfo = new List<UserInfoModel>();
List<myuser_field> myUserFields = GetMyUserFields();
var otherUserFields = otherUserService.GetOtherUserFields();
userInfo = (from otherUserField in otherUserFields
where otherUserField.Chosen == true
select new UserInfoModel {
MyCaption = otherUserField.FieldAlias,
MyValue =
}).ToList();
MyCaption我直接從列表中獲得一個。現在要獲取MyValue,我需要根據otherUserField.FieldName來查找。 即我必須找到myUserFields.FieldName,它等於otherUserField.FieldName並將其分配給MyValue。
可以在上面的單個查詢中完成嗎?請建議
您可以使用帶有兩個集合聯接:HTTP:// weblogs.asp.net/rajbk/archive/2010/03/12/joins-in-linq-to-sql.aspx – H27studio