Click here to Skip to main content
14,364,863 members
   

C#

 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Gerry Schmitz8-Apr-19 6:39
mveGerry Schmitz8-Apr-19 6:39 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn8-Apr-19 12:50
professionalLuc Pattyn8-Apr-19 12:50 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol9-Apr-19 10:14
memberMou_kol9-Apr-19 10:14 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol11-Apr-19 9:58
memberMou_kol11-Apr-19 9:58 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn11-Apr-19 10:17
professionalLuc Pattyn11-Apr-19 10:17 
QuestionHow to do three join between three list Pin
Mou_kol7-Apr-19 9:12
memberMou_kol7-Apr-19 9:12 
AnswerRe: How to do three join between three list Pin
Vinod Jangle9-Apr-19 4:22
memberVinod Jangle9-Apr-19 4:22 
QuestionRepeated join causing poor performance in for loop Pin
Mou_kol7-Apr-19 9:10
memberMou_kol7-Apr-19 9:10 
My problem is that when there are 50 or 100 iterations in for loop and doing repeated join between list & datatable, then my code takes long time to run about 10 minute.

if (lst_Broker_BrokerBogey_collection.Any())
{
    foreach (var objbrokerBrogeyData in lst_Broker_BrokerBogey_collection)
    {

        string brokerBogeypath = File.Exists(@Path.Combine(ConfigurationManager.AppSettings["DBPath"].ToString(), cmbTicker.Text, "###~$$$~Bogey.xml".Replace("###", cmbTicker.Text).Trim().Replace("$$$", objbrokerBrogeyData.Broker).Trim())) ?
        @Path.Combine(ConfigurationManager.AppSettings["DBPath"].ToString(), cmbTicker.Text, "###~$$$~Bogey.xml".Replace("###", cmbTicker.Text).Trim().Replace("$$$", objbrokerBrogeyData.Broker).Trim()) : ""; ;

        if (!String.IsNullOrEmpty(brokerBogeypath))
        {
            bool selectedBroker = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Select")).Equals("True") ? true : false;
            if (selectedBroker)
            {
                RDSS_Workbench.QcVerticalViewNew.QcVerticalViewNewProcess.BrokerCodeBrokerNameBrokerBogey objBrokerCodeBrokerNameBrokerBogey
                    = new QcVerticalViewNew.QcVerticalViewNewProcess.BrokerCodeBrokerNameBrokerBogey();

                objBrokerCodeBrokerNameBrokerBogey.BrokerCode = objbrokerBrogeyData.Broker;
                objBrokerCodeBrokerNameBrokerBogey.IsAllowEstimate = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Select Estim.")).Equals("True") ? true : false; //objbrokerBrogeyData._willpassEstimatePeriods;
                objBrokerCodeBrokerNameBrokerBogey.IsHistoric = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Historical")).Equals("True") ? true : false; //objbrokerBrogeyData._followHistoricalData;
                objBrokerCodeBrokerNameBrokerBogey.ReviseDate = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Model Date"));
                objBrokerCodeBrokerNameBrokerBogey.BrokerEarnings = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Earnings"));

                DataTable GeneralBrokerDt = new DataTable();
                GeneralBrokerDt = objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GetBrokerBogey(@brokerBogeypath).Tables[2]; //objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GneralBorgeyDt.Tables[2];

                List<QCHelper> qclist = new List<QCHelper>();

                qclist = (from cf in cfToggleList
                          join broker in GeneralBrokerDt.AsEnumerable()
                       on new { val = cf.Section.Trim().ToUpper(), val1 = cf.Li.Trim().ToUpper(), val2 = cf.StandardDate.Replace("A", "").Replace("E", "").Trim().ToUpper() }
                       equals new { val = broker.Field<string>("TabName").Trim().ToUpper(), val1 = broker.Field<string>("StandardLineitem").Trim().ToUpper(), val2 = broker.Field<string>("StandardDate").Replace("A", "").Replace("E", "").Trim().ToUpper() }
                       into tempJoin
                          from leftJoin in tempJoin.DefaultIfEmpty()
                          where cf.Broker == objBrokerCodeBrokerNameBrokerBogey.BrokerCode
                          select new QCHelper()
                          {
                              Broker = cf.Broker,
                              BrokerName = cf.BrokerName,
                              Section = cf.Section,
                              BrokerEarnings = objBrokerCodeBrokerNameBrokerBogey.BrokerEarnings,
                              Li = cf.Li,
                              StandardDate = leftJoin == null ? cf.StandardDate : leftJoin.Field<string>("StandardDate"),
                              xFundCode = cf.xFundCode,
                              StandardValue = leftJoin == null ? string.Empty : leftJoin.Field<string>("StandardValue"),
                              IsAllowEstimate = objBrokerCodeBrokerNameBrokerBogey.IsAllowEstimate,
                              ReviseDate = objBrokerCodeBrokerNameBrokerBogey.ReviseDate
                          }).ToList<QCHelper>();

                GeneralBrokerDt.Dispose();
                GeneralBrokerDt = null;
                objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GneralBorgeyDt.Dispose();
                objBrokerCodeBrokerNameBrokerBogey.brokerbogeycontainer.GneralBorgeyDt = null;

                if (qclist.Count > 0)
                    lstBorkerWiseData.AddRange(qclist);

                qclist = null;
                objBrokerCodeBrokerNameBrokerBogey = null;
            }
        }
    }


This is my list lst_Broker_BrokerBogey_collection in which I need to iterate. brokerBogeypath will have multiple different file location in loop.

This line:

bool selectedBroker = (dtdgvBrokers.AsEnumerable().FirstOrDefault(x => x.Field<string>("Brokers").Equals(objbrokerBrogeyData.Broker)).Field<string>("Select")).Equals("True") ? true : false;


dtdgvBrokers is datagridview and in selectedBroker variable will have true false value based on grid select value.

If selected broker has true value, then load datatable GeneralBrokerDt. GetBrokerBogey() function will load data from different xml file in each for loop iteration.

in next line
qclist = (from cf in cfToggleList
join broker in GeneralBrokerDt.AsEnumerable()


I am joining list cfToggleList and datatable GeneralBrokerDt.

Can you review it for performance and best coding practices?
AnswerRe: Repeated join causing poor performance in for loop Pin
jschell7-Apr-19 9:57
memberjschell7-Apr-19 9:57 
GeneralRe: Repeated join causing poor performance in for loop Pin
Mou_kol8-Apr-19 10:07
memberMou_kol8-Apr-19 10:07 
AnswerRe: Repeated join causing poor performance in for loop Pin
Luc Pattyn7-Apr-19 16:44
professionalLuc Pattyn7-Apr-19 16:44 
GeneralRe: Repeated join causing poor performance in for loop Pin
Mou_kol8-Apr-19 10:13
memberMou_kol8-Apr-19 10:13 
GeneralRe: Repeated join causing poor performance in for loop Pin
Luc Pattyn8-Apr-19 10:14
professionalLuc Pattyn8-Apr-19 10:14 
QuestionC# List: How to do 3 joins for better performance Pin
Mou_kol7-Apr-19 3:44
memberMou_kol7-Apr-19 3:44 
AnswerRe: C# List: How to do 3 joins for better performance Pin
Gerry Schmitz7-Apr-19 7:17
mveGerry Schmitz7-Apr-19 7:17 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Mou_kol7-Apr-19 9:06
memberMou_kol7-Apr-19 9:06 
AnswerRe: C# List: How to do 3 joins for better performance Pin
Dave Kreskowiak7-Apr-19 7:39
mveDave Kreskowiak7-Apr-19 7:39 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Mou_kol7-Apr-19 9:05
memberMou_kol7-Apr-19 9:05 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Dave Kreskowiak7-Apr-19 9:29
mveDave Kreskowiak7-Apr-19 9:29 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Mou_kol8-Apr-19 10:06
memberMou_kol8-Apr-19 10:06 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Dave Kreskowiak8-Apr-19 10:24
mveDave Kreskowiak8-Apr-19 10:24 
AnswerRe: C# List: How to do 3 joins for better performance Pin
Mycroft Holmes7-Apr-19 13:17
memberMycroft Holmes7-Apr-19 13:17 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Mou_kol8-Apr-19 10:09
memberMou_kol8-Apr-19 10:09 
QuestionHow to make code run differently depending on the platform it is running on? Pin
Xarzu5-Apr-19 7:44
memberXarzu5-Apr-19 7:44 
AnswerRe: How to make code run differently depending on the platform it is running on? Pin
Richard Deeming5-Apr-19 8:15
mveRichard Deeming5-Apr-19 8:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.