Linq查询和循环 [英] Linq query and looping
问题描述
表格中的示例数据:表格名称 - 供应商
和实体名称 - dbData
Sample data from table: Table Name - SUPPLIERS
and Entity Name - dbData
RECORD_NO ID_NO FIRST_BRANCH SECOND_BRANCH POSITION
----------------------------------------------------------------
1 05100242 05100243 05100244 L
2 05200443 05100245 05100247 L
3 05100244 05100248 R
4 05100245 05100249 L
5 05100247 05100250 R
6 05100248 L
7 05100249 L
8 05100250 L
如果你得到 05100242
的所有分支,请使用查询
if you get all the branch of 05100242
, use the query
int suppliers = dbData.SUPPLIERS.where(x=>x.RECORD_NO !=1).Count();
问题是你如何获得 05100243的
& SUPPLIERS(COUNT)
05100244
使用查询和循环或任何方法来获得结果?
获得<$的结果c $ c> 05100242 我用过
The question is how are you going to get the SUPPLIERS(COUNT)
of 05100243
& 05100244
using query and loop or any method use to get the results?
To get the result of 05100242
I used
var data = dbData.SUPPLIERS.where(x=>x.ID_NO == 05100242);
string left = data.FIRST_BRANCH;
var leftbranch = dbData.where(x=>x.ID_NO == left);
string right = data.SECOND_BRANCH;
var leftbranch = dbData.where(x=>x.ID_NO == right);
您可以使用该方法,但手动说话,您不知道如何停止和行数,因为它正在增加。
任何知道此解决方案的人?使用将计算左侧和右侧的类?
You can use that method but manually speaking,you didn''t know how to stop and how many rows because it is increasing.
Anyone who knows the solution for this? using a class that will count the left and right side?
推荐答案
用LINQ替换foreach循环 [ ^ ]应该可以帮助你入门。
你最好试一试,然后拿出来如果您遇到任何其他问题。
Replacing foreach loop with LINQ[^] should help you get started.
Its best you give this a try and then come up with further issues if you face any.
这篇关于Linq查询和循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!