none
How to use PLINQ for my scenario RRS feed

  • Question

  • see my LINQ query and tell me how to use PLINQ to speed up.

     var WeitageWiseRow = (from tickerBrokerStandardDateLineitemValue in MergedataPerBroker
                                              group tickerBrokerStandardDateLineitemValue by new
                                              {
                                                  Section = tickerBrokerStandardDateLineitemValue.TabName,
                                                  LineItem = tickerBrokerStandardDateLineitemValue.StandardLineItem,
                                              } into tickerBrokerStandardDateLineitemValuesGroup
                                              orderby tickerBrokerStandardDateLineitemValuesGroup.Key.Section
                                              select new
                                              {
                                                  Section = tickerBrokerStandardDateLineitemValuesGroup.Key.Section,
                                                  LineItem = tickerBrokerStandardDateLineitemValuesGroup.Key.LineItem,
                                                  BrokerGroupData = tickerBrokerStandardDateLineitemValuesGroup.GroupBy(y => y.BrokerName)
                                              }).ToList();
    help me with sample code. thanks

    Tuesday, January 15, 2019 2:56 PM

Answers

  • Hi Studip_inn,

    Thank you for posting here.

    For your question, due to the code you provided is not completed, I could not test the code.

    Normally, through parallel execution for PLINQ, we often just add the AsParallel query operation to the data source like the code below.

    var WeitageWiseRow = (from tickerBrokerStandardDateLineitemValue in MergedataPerBroker.AsParallel()
                                              group tickerBrokerStandardDateLineitemValue by new
                                              {
                                                  Section = tickerBrokerStandardDateLineitemValue.TabName,
                                                  LineItem = tickerBrokerStandardDateLineitemValue.StandardLineItem,
                                              } into tickerBrokerStandardDateLineitemValuesGroup
                                              orderby tickerBrokerStandardDateLineitemValuesGroup.Key.Section
                                              select new
                                              {
                                                  Section = tickerBrokerStandardDateLineitemValuesGroup.Key.Section,
                                                  LineItem = tickerBrokerStandardDateLineitemValuesGroup.Key.LineItem,
                                                  BrokerGroupData = tickerBrokerStandardDateLineitemValuesGroup.GroupBy(y => y.BrokerName)
                                              }).ToList();

    For more details, you could check the examples in the code project.

    https://www.codeproject.com/Articles/156980/Parallelism-in-NET-PLINQ

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Wednesday, January 16, 2019 5:42 PM
    Wednesday, January 16, 2019 5:32 AM
    Moderator

All replies

  • Someone other than you is using PLINQ? :)
    Tuesday, January 15, 2019 4:33 PM
  • Hi Studip_inn,

    Thank you for posting here.

    For your question, due to the code you provided is not completed, I could not test the code.

    Normally, through parallel execution for PLINQ, we often just add the AsParallel query operation to the data source like the code below.

    var WeitageWiseRow = (from tickerBrokerStandardDateLineitemValue in MergedataPerBroker.AsParallel()
                                              group tickerBrokerStandardDateLineitemValue by new
                                              {
                                                  Section = tickerBrokerStandardDateLineitemValue.TabName,
                                                  LineItem = tickerBrokerStandardDateLineitemValue.StandardLineItem,
                                              } into tickerBrokerStandardDateLineitemValuesGroup
                                              orderby tickerBrokerStandardDateLineitemValuesGroup.Key.Section
                                              select new
                                              {
                                                  Section = tickerBrokerStandardDateLineitemValuesGroup.Key.Section,
                                                  LineItem = tickerBrokerStandardDateLineitemValuesGroup.Key.LineItem,
                                                  BrokerGroupData = tickerBrokerStandardDateLineitemValuesGroup.GroupBy(y => y.BrokerName)
                                              }).ToList();

    For more details, you could check the examples in the code project.

    https://www.codeproject.com/Articles/156980/Parallelism-in-NET-PLINQ

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sudip_inn Wednesday, January 16, 2019 5:42 PM
    Wednesday, January 16, 2019 5:32 AM
    Moderator
  • see this LINQ query. please tell me how to use PLINQ here in my below query. if possible please give me a another version of same code where PLINQ will be used. thanks

                            var QCViewAllHistValue = (from viewalllst in QCViewAllBrokerList
                                                      join frmlst in customformulaList
                                                      on new
                                                      {
                                                          val = String.IsNullOrEmpty(viewalllst.ViewAllSection) ? "" : viewalllst.ViewAllSection.Trim().ToUpper(),
                                                          val1 = String.IsNullOrEmpty(viewalllst.ViewAllLineItem) ? "" : viewalllst.ViewAllLineItem.Trim().ToUpper(),
                                                          val2 = String.IsNullOrEmpty(viewalllst.ViewAllPeriod) ? "" : viewalllst.ViewAllPeriod.Replace("A", "").Replace("E", "").Trim().ToUpper(),
                                                          val3 = String.IsNullOrEmpty(viewalllst.ViewAllBroker) ? "" : viewalllst.ViewAllBroker.Trim().ToUpper()
                                                      }
    
                                                      equals new
                                                      {
                                                          val = String.IsNullOrEmpty(frmlst.Section) ? "" : frmlst.Section.Trim().ToUpper(),
                                                          val1 = String.IsNullOrEmpty(frmlst.Li) ? "" : frmlst.Li.Trim().ToUpper(),
                                                          val2 = String.IsNullOrEmpty(frmlst.Period) ? "" : frmlst.Period.Replace("A", "").Replace("E", "").Trim().ToUpper(),
                                                          val3 = String.IsNullOrEmpty(frmlst.Broker) ? "" : frmlst.Broker.Trim().ToUpper()
    
                                                      }
                                                      into tempJoin
                                                      from leftJoin in tempJoin.DefaultIfEmpty()
                                                      where viewalllst.Wtg == "1"
                                                      select new QCHelper()
                                                      {
                                                          Broker = viewalllst.ViewAllBroker == null ? string.Empty : viewalllst.ViewAllBroker,
                                                          Section = viewalllst.ViewAllSection == null ? string.Empty : viewalllst.ViewAllSection,
                                                          Li = viewalllst.ViewAllLineItem == null ? string.Empty : viewalllst.ViewAllLineItem,
                                                          Period = viewalllst.ViewAllPeriod == null ? string.Empty : viewalllst.ViewAllPeriod,
                                                          CrossCalc1Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc1Q,
                                                          CrossCalc2Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc2Q,
                                                          CrossCalc3Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc3Q,
                                                          CrossCalc4Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc4Q,
                                                          CrossCalcFY = leftJoin == null ? string.Empty : leftJoin.CrossCalcFY,
                                                          Value = viewalllst.Value == null ? string.Empty : viewalllst.Value,
                                                          QCFormula = leftJoin == null ? string.Empty : leftJoin.QCFormula,
                                                          CustomFormula = leftJoin == null ? string.Empty : leftJoin.CustomFormula,
                                                          Historical = leftJoin == null ? string.Empty : String.IsNullOrEmpty(leftJoin.Historical) ? "" : leftJoin.Historical,
                                                          DeriveCrossCalc = leftJoin == null ? string.Empty : leftJoin.DeriveCrossCalc
                                                      }).ToList<QCHelper>();

    Friday, January 18, 2019 7:57 AM
  • one request Sir @Wendy that please see my new linq code with multiple join and tell me how to use AsParallel() there.

    var QCViewAllHistValue = (from viewalllst in QCViewAllBrokerList
                                                      join frmlst in customformulaList
                                                      on new
                                                      {
                                                          val = String.IsNullOrEmpty(viewalllst.ViewAllSection) ? "" : viewalllst.ViewAllSection.Trim().ToUpper(),
                                                          val1 = String.IsNullOrEmpty(viewalllst.ViewAllLineItem) ? "" : viewalllst.ViewAllLineItem.Trim().ToUpper(),
                                                          val2 = String.IsNullOrEmpty(viewalllst.ViewAllPeriod) ? "" : viewalllst.ViewAllPeriod.Replace("A", "").Replace("E", "").Trim().ToUpper(),
                                                          val3 = String.IsNullOrEmpty(viewalllst.ViewAllBroker) ? "" : viewalllst.ViewAllBroker.Trim().ToUpper()
                                                      }
    
                                                      equals new
                                                      {
                                                          val = String.IsNullOrEmpty(frmlst.Section) ? "" : frmlst.Section.Trim().ToUpper(),
                                                          val1 = String.IsNullOrEmpty(frmlst.Li) ? "" : frmlst.Li.Trim().ToUpper(),
                                                          val2 = String.IsNullOrEmpty(frmlst.Period) ? "" : frmlst.Period.Replace("A", "").Replace("E", "").Trim().ToUpper(),
                                                          val3 = String.IsNullOrEmpty(frmlst.Broker) ? "" : frmlst.Broker.Trim().ToUpper()
    
                                                      }
                                                      into tempJoin
                                                      from leftJoin in tempJoin.DefaultIfEmpty()
                                                      where viewalllst.Wtg == "1"
                                                      select new QCHelper()
                                                      {
                                                          Broker = viewalllst.ViewAllBroker == null ? string.Empty : viewalllst.ViewAllBroker,
                                                          Section = viewalllst.ViewAllSection == null ? string.Empty : viewalllst.ViewAllSection,
                                                          Li = viewalllst.ViewAllLineItem == null ? string.Empty : viewalllst.ViewAllLineItem,
                                                          Period = viewalllst.ViewAllPeriod == null ? string.Empty : viewalllst.ViewAllPeriod,
                                                          CrossCalc1Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc1Q,
                                                          CrossCalc2Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc2Q,
                                                          CrossCalc3Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc3Q,
                                                          CrossCalc4Q = leftJoin == null ? string.Empty : leftJoin.CrossCalc4Q,
                                                          CrossCalcFY = leftJoin == null ? string.Empty : leftJoin.CrossCalcFY,
                                                          Value = viewalllst.Value == null ? string.Empty : viewalllst.Value,
                                                          QCFormula = leftJoin == null ? string.Empty : leftJoin.QCFormula,
                                                          CustomFormula = leftJoin == null ? string.Empty : leftJoin.CustomFormula,
                                                          Historical = leftJoin == null ? string.Empty : String.IsNullOrEmpty(leftJoin.Historical) ? "" : leftJoin.Historical,
                                                          DeriveCrossCalc = leftJoin == null ? string.Empty : leftJoin.DeriveCrossCalc
                                                      }).ToList<QCHelper>();

    • Edited by Sudip_inn Sunday, January 20, 2019 11:10 AM
    Sunday, January 20, 2019 11:10 AM