C# 用LINQ c检索数据#
我有以下问题 客户和客户 每个客户都链接到一个特定的客户 -ClientID、ClientName、Customer\u custID -CustomerID,CustomerName 我想检索与特定客户相关的每个客户 这是我的尝试C# 用LINQ c检索数据#,c#,linq,C#,Linq,我有以下问题 客户和客户 每个客户都链接到一个特定的客户 -ClientID、ClientName、Customer\u custID -CustomerID,CustomerName 我想检索与特定客户相关的每个客户 这是我的尝试 data=clients.select(c=>c.clientName, c.customerName.where(f>f.customerID==f.customer_custID) 我知道这是非常错误的,但我只是在学习l
data=clients.select(c=>c.clientName,
c.customerName.where(f>f.customerID==f.customer_custID)
我知道这是非常错误的,但我只是在学习lamda表达式和LINQ,所以请原谅我试试这个:
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;
IEnumerable客户端=…..//你的客户收藏
IEnumerable customers=..//您的客户收藏
var relatedClients=来自客户中的cst
将cli加入cst上的客户端。CustomerID等于cli.Customer\u custID
其中cst.CustomerID==0//您的CustomerID
选择cli;
我希望我正确理解了您的要求。它假定您在输入查询之前知道要查找的客户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!
}
您对特定客户了解多少?客户ID还是客户名称?客户机和客户机类是什么样子的?您可以做
data=clients.where(c=>c.customer\u custID==customerID)代码>?请阅读更多教程,回来再试一次。这根本不需要编译。为了方便起见,您需要阅读更多关于延迟加载的内容