How to do left and inner join in same query
-
See my linq query first
var query = (from r1 in dtMappedSectionNotEmpty.AsEnumerable()
join r2 in dtData.AsEnumerable()
on r1.Field("Row").Trim().ToUpper() equals r2.Field("RowCoordinate").Trim().ToUpper()
join r3 in _Periods.AsEnumerable()
on r2.Field("StandardDate").Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper() equals r3.Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper()
where r1.Field("Tab").Trim().ToUpper() == strTab.Trim().ToUpper()
select new BrokerData
{
RowNumber = r1.Field("Row") ?? "0",
TabName = r1.Field("Matched Section") ?? "",
StandardDate = r3.ToString(),
BRTab = r1.Field("Tab") ?? "",
BRLineItem = r1.Field("Broker Items") ?? "",
Action = r1.Field("Action") ?? "",
StandardLineItem = r1.Field("Matched Items") ?? "",
StandardValue =r2.Field("LineItemDateValue") ?? ""
}).ToList();in my above code there are 2 datatable and one list. now i am not being able to compose left and inner join in same query. there will be left join between dtMappedSectionNotEmpty and dtData datatable. means left join between r1 & r2 again there will be inner join between dtData & _Periods means i want inner join between r2 & r3 so please see my code and give me another set same LINQ code where left join and inner join will be there in same query. thanks
-
See my linq query first
var query = (from r1 in dtMappedSectionNotEmpty.AsEnumerable()
join r2 in dtData.AsEnumerable()
on r1.Field("Row").Trim().ToUpper() equals r2.Field("RowCoordinate").Trim().ToUpper()
join r3 in _Periods.AsEnumerable()
on r2.Field("StandardDate").Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper() equals r3.Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper()
where r1.Field("Tab").Trim().ToUpper() == strTab.Trim().ToUpper()
select new BrokerData
{
RowNumber = r1.Field("Row") ?? "0",
TabName = r1.Field("Matched Section") ?? "",
StandardDate = r3.ToString(),
BRTab = r1.Field("Tab") ?? "",
BRLineItem = r1.Field("Broker Items") ?? "",
Action = r1.Field("Action") ?? "",
StandardLineItem = r1.Field("Matched Items") ?? "",
StandardValue =r2.Field("LineItemDateValue") ?? ""
}).ToList();in my above code there are 2 datatable and one list. now i am not being able to compose left and inner join in same query. there will be left join between dtMappedSectionNotEmpty and dtData datatable. means left join between r1 & r2 again there will be inner join between dtData & _Periods means i want inner join between r2 & r3 so please see my code and give me another set same LINQ code where left join and inner join will be there in same query. thanks
Use "intermediate" queries. LINQ will do the same internally. There is nothing special or heroic in doing it in the "same query".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Use "intermediate" queries. LINQ will do the same internally. There is nothing special or heroic in doing it in the "same query".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
i know i can break the query into two separate to achieve this job but i need to know if i want to do left & inner join in same query then how could i compose it. i stuck for syntax. if you know then post a sample LINQ query where left & inner join will be performed in same query. thanks