LINQ: How to do conditional joining by LINQ to Object

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
i am doing LINQ to Object query. i have two list where i am doing joining based on few fields.

i need to do conditional joining like when viewalllst.xFundCode start with DS then joining will be perform on frmlst.Li else frmlst.xFundCode

i am talking about this area....see my below code

viewalllst is not getting available for first on block for join

on new
{
val = String.IsNullOrEmpty(frmlst.Section) ? "" : frmlst.Section.Trim().ToUpper(),
//val1 = String.IsNullOrEmpty(frmlst.Li) ? "" : frmlst.Li.Trim().ToUpper(),
val1 = String.IsNullOrEmpty(frmlst.xFundCode) ? "" : frmlst.xFundCode.Trim(),
val2 = String.IsNullOrEmpty(frmlst.Period) ? "" : frmlst.Period.Replace("A", "").Replace("E", "").Trim().ToUpper(),
val3 = String.IsNullOrEmpty(frmlst.Broker) ? "" : frmlst.Broker.Trim().ToUpper()
}


full code

var QCViewAllHistValue = (from frmlst in cfList
join viewalllst in QCViewAllBrokerList
on new
{
val = String.IsNullOrEmpty(frmlst.Section) ? "" : frmlst.Section.Trim().ToUpper(),
//val1 = String.IsNullOrEmpty(frmlst.Li) ? "" : frmlst.Li.Trim().ToUpper(),
val1 = String.IsNullOrEmpty(frmlst.xFundCode) ? "" : frmlst.xFundCode.Trim(),
val2 = String.IsNullOrEmpty(frmlst.Period) ? "" : frmlst.Period.Replace("A", "").Replace("E", "").Trim().ToUpper(),
val3 = String.IsNullOrEmpty(frmlst.Broker) ? "" : frmlst.Broker.Trim().ToUpper()
}
equals new
{
val = String.IsNullOrEmpty(viewalllst.ViewAllSection) ? "" : viewalllst.ViewAllSection.Trim().ToUpper(),
//val1 = String.IsNullOrEmpty(viewalllst.ViewAllLineItem) ? "" : viewalllst.ViewAllLineItem.Trim().ToUpper(),
val1 = String.IsNullOrEmpty(viewalllst.xFundCode) ? "" : viewalllst.xFundCode.Trim(),
val2 = String.IsNullOrEmpty(viewalllst.ViewAllPeriod) ? "" : viewalllst.ViewAllPeriod.Replace("A", "").Replace("E", "").Trim().ToUpper(),
val3 = String.IsNullOrEmpty(viewalllst.ViewAllBroker) ? "" : viewalllst.ViewAllBroker.Trim().ToUpper()
}

into tempJoin
from leftJoin in tempJoin.DefaultIfEmpty()
select new QCHelper()
{
Broker = frmlst == null ? string.Empty : frmlst.Broker == null ? string.Empty : frmlst.Broker,
Section = frmlst == null ? string.Empty : frmlst.Section == null ? string.Empty : frmlst.Section,
Li = frmlst == null ? string.Empty : frmlst.Li == null ? string.Empty : frmlst.Li,
Period = frmlst == null ? string.Empty : frmlst.Period == null ? string.Empty : frmlst.Period,
CrossCalc1Q = frmlst == null ? string.Empty : frmlst.CrossCalc1Q == null ? string.Empty : frmlst.CrossCalc1Q,
CrossCalc2Q = frmlst == null ? string.Empty : frmlst.CrossCalc2Q == null ? string.Empty : frmlst.CrossCalc2Q,
CrossCalc3Q = frmlst == null ? string.Empty : frmlst.CrossCalc3Q == null ? string.Empty : frmlst.CrossCalc3Q,
CrossCalc4Q = frmlst == null ? string.Empty : frmlst.CrossCalc4Q == null ? string.Empty : frmlst.CrossCalc4Q,
CrossCalcFY = frmlst == null ? string.Empty : frmlst.CrossCalcFY == null ? string.Empty : frmlst.CrossCalcFY,
Value = leftJoin == null ? string.Empty : (leftJoin.Value == null ? string.Empty : leftJoin.Value),


}).ToList<QCHelper>();

please share some code or suggestion how to do my task. thanks

Continue reading...
 
Back
Top