在这种情况下,我必须将一个系统中的多个客户编号与另一个系统中的单个客户编号进行匹配。
例如,系统A中的客户编号225、228和223都将映射到系统B中的客户编号110022。
很简单,我有一个矩阵设置来完成。
我将矩阵数据按如下方式拉入:
 var dt_th_matrix = (from m in aDb.Matrix_Datatrac_TopHat select m).ToArray();
所以记录应该是这样的:
客户:3客户:1001
客户:4客户:1001
客户:5客户:1002
然后我做了一个大数据拉和步骤通过所有项目。对于每一个项目,我都从矩阵中获取匹配的客户编号,如下所示:
foreach (var dt_stop in mainPull)
{
int? th_customerId = (from d in dt_th_matrix
where d.datatrac_customer_no == dt_stop.Customer_No.ToString()
select d.tophat_customer_detail_Id).First();
我更愿意做的是将代码直接嵌入到我的数据拉取中,从矩阵中获取客户编号——“查询不知何故地出现在这里”这一部分将是我假定的某种类型的lambda。有什么帮助吗?
我试过这样的方法:
th_customerId = (dt_th_matrix.First().tophat_customer_detail_Id.Equals c.Customer_No)
但事实并非如此(显然)
var mainPull = (from c in cDb.DistributionStopInformations
join rh in cDb.DistributionRouteHeaders on c.Route_Code equals rh.Route_Code
where c.Company_No == 1 &&
(accountNumbers.Contains(c.Customer_No)) &&
(brancheSearchList.Contains(c.Branch_Id) && brancheSearchList.Contains(rh.Branch_Id)) &&
c.Shipment_Type == "D" &&
(c.Datetime_Created > dateToSearch || c.Datetime_Updated > dateToSearch) &&
rh.Company_No == 1 &&
((rh.Route_Date == routeDateToSearch && c.Route_Date == routeDateToSearch) ||
(rh.Route_Date == routeDateToSearch.AddDays(1) && c.Route_Date == routeDateToSearch.AddDays(1)))
orderby c.Unique_Id_No
select new
{
c.Datetime_Updated,
th_customerId = ("Query goes here somehow")
c.Datetime_Created,
c.Unique_Id_No,
c.Original_Unique_Id_No,
c.Unique_Id_Of_New_Stop,
c.Branch_Id,
c.Route_Date,
c.Route_Code,
c.Sequence_Code,
c.Customer_No,
c.Customer_Reference,
c.Shipment_Type,
c.Stop_Name,
c.Stop_Address,
c.Stop_City,
c.Stop_State,
c.Stop_Zip_Postal_Code,
c.Stop_Phone_No,
c.Stop_Arrival_Time,
c.Stop_Departure_Time,
c.Address_Point,
c.Stop_Special_Instruction1,
c.Stop_Special_Instruction2,
c.Stop_Expected_Pieces,
c.Stop_Expected_Weight,
c.Stop_Signature,
c.Actual_Arrival_Time,
c.Actual_Depart_Time,
c.Actual_Service_Date,
c.Stop_Actual_Pieces,
c.Stop_Exception_Code,
c.Created_By,
rh_Route_Date = rh.Route_Date,
routeHeaderRouteCode = rh.Route_Code,
rh.Actual_Driver,
rh.Assigned_Driver,
rh_routeDate = rh.Route_Date
}).ToArray();
我将努力澄清上述问题。
我需要Linq查询说:
对于我拉的每个记录,我将转到名为dt_th_matrix的数组,并获取与此行匹配的记录并使用它。
矩阵中的数据如下所示:
记录1:datatrac_客户编号:227,Tophat_客户详细信息_ID 1
记录2:datatrac_客户编号:228,Tophat_客户详细信息:1
记录3:datatrac_客户编号910,Tophat_客户详细信息ID:5
然后,对于在mainpull中提取的第一条记录,字段c.customer_no==228,因此我需要在select new语句中进行查询,以将该customerID替换为1(来自矩阵中的记录2)。
然后说在mainpull中拉入的下一个记录在c.customer_no=910字段中,则th_customerID将为5。
这就是我的foreach语句的第一行当前正在做的。我想把这个逻辑转移到我的LINQ查询中。