我有以下问题
客户和客户 每个客户都链接到特定客户
-ClientID,ClientName,Customer_custID
-CustomerID,客户名称
我想检索与特定客户相关的每个客户
这是我的尝试
data=clients.select(c=>c.clientName,
c.customerName.where(f>f.customerID==f.customer_custID)
我知道这非常错,但我只是在学习lamda表达式和LINQ,所以请原谅我
答案 0 :(得分:0)
试试这个:
IEnumerable<Client> clients = .... // your clients collection
IEnumerable<Customer> customers = .... // your customers collection
var relatedClients = from cst in customers
join cli in clients on cst.CustomerID equals cli.Customer_custID
where cst.CustomerID == 0 // your customerID
select cli;
答案 1 :(得分:0)
我希望我能理解你想要的东西。它假定您在输入查询之前知道您要查找的客户ID。
var clientsQuery = from clients in Client
where clients.Customer_custId == customerId
select clients;
然后,您可以foreach
查询结果。
foreach (var client in clientsQuery)
{
// Do stuff with your clients!
}