![](/img/trans.png)
[英]How to create a query to get only N entries from a list in certain record in MongoDB and C#?
[英]How to get only one value from the record in the list in c#?
我有兩個自定義列表:
List<Detailsofemployee> empDetails = new List<Detailsofemployee>();
List<regionDetails> regDetails = new List<regionDetails>();
empDetails
值為{"1","Sam","IT"}
。 regDetails
值為{"IT","UK"}
。 我想從第一個列表中獲取數據,並據此從另一個列表中獲取數據
var det = (from l in empDetails where l.ID == "1" select l.Department)
var region = (from l in regDetails where l.Department == det select l.Country)
如何獲得det = "IT"
?
帶有檢查和用戶輸入值
using System.Linq;
var userInputId = //user input value
var emp = empDetails.FirstOrDefault(x => x.Id == userInputId);
var regDetail = new regionDetails();
if (emp != null)
{
regDetail = regDetails.FirstOrDefault(c => c.Department == emp.Department);
}
if (regDetail != null)
{
return regDetail.Country;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.