我有我的代码中的瓶颈,我想,以消除特定的问题,但我想一般都知道,对于未来,我将如何去寻找快速哪里会出现瓶颈,而不必重新发明轮子。
这里是我的方法的代码,但就像我说的,我想知道如何普遍找出LINQ查询多长时间服用或数据表上采取多长时间建成,等....
public static DataTable GetPivotDataTable(this IQueryable<WbsNumber> table, Months month)
{
FmToolDataContext dataContext = new FmToolDataContext();
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("wbsNumber", typeof(string));
dt.Columns.Add("wbsTitle", typeof(string));
dt.Columns.Add("number", typeof(string));
dt.Columns.Add("vendor", typeof(string));
dt.Columns.Add("programFund", typeof(string));
dt.Columns.Add("committedAmount", typeof(decimal));
dt.Columns.Add("obligatedAmount", typeof(decimal));
dt.Columns.Add("costedAmount", typeof(decimal));
dt.Columns.Add("costOverObligationsAmount", typeof(decimal));
foreach (WbsNumber wbs in table)
{
// Get PRs for this Project Detail
var prAmounts = dataContext.PrAmounts.Where(_pra => _pra.isCurrent && !_pra.requiresAudit
&& _pra.PrDetail.isActive && _pra.PrDetail.WbsNumber == wbs
&& _pra.Import.fiscalYear == (int)HttpContext.Current.Session["FiscalYear"]);
foreach(PrAmount pra in prAmounts)
{
DataRow row = dt.NewRow();
row["id"] = wbs.id;
row["wbsNumber"] = wbs.displayString;
row["wbsTitle"] = wbs.wbsTitlesId != null ? wbs.WbsTitle.name : "(blank)";
row["number"] = pra.PrDetail.Pr.number;
row["vendor"] = pra.PrDetail.Pr.GetPrVendorName();
row["programFund"] = pra.PrDetail.ProgramFund.name;
row["committedAmount"] = pra.CommittedMonthlyRecord.GetMonth(month);
row["obligatedAmount"] = pra.ObligatedMonthlyRecord.GetMonth(month);
row["costedAmount"] = pra.CostedMonthlyRecord.GetMonth(month);
row["costOverObligationsAmount"] = pra.CostOverObligationsMonthlyRecord.GetMonth(month);
dt.Rows.Add(row);
}
// Get the P-Cards for this Project Detail
var pCardAmounts = dataContext.PCardAmounts.Where(_pca => _pca.isCurrent && !_pca.requiresAudit
&& _pca.PCardTransaction.isActive && _pca.PCardTransaction.WbsNumber == wbs
&& _pca.Import.fiscalYear == (int)HttpContext.Current.Session["FiscalYear"]);
foreach (PCardAmount pca in pCardAmounts)
{
DataRow row = dt.NewRow();
row["id"] = wbs.id;
row["wbsNumber"] = wbs.displayString;
row["wbsTitle"] = wbs.wbsTitlesId != null ? wbs.WbsTitle.name : "(blank)";
row["number"] = pca.PCardTransaction.number;
row["vendor"] = pca.PCardTransaction.bwVendorsId != null ? pca.PCardTransaction.BwVendor.name : "(blank)";
row["programFund"] = pca.PCardTransaction.ProgramFund.name;
row["committedAmount"] = pca.CommittedMonthlyRecord.GetMonth(month);
row["obligatedAmount"] = pca.ObligatedMonthlyRecord.GetMonth(month);
row["costedAmount"] = pca.CostedMonthlyRecord.GetMonth(month);
row["costOverObligationsAmount"] = pca.CostOverObligationsMonthlyRecord.GetMonth(month);
dt.Rows.Add(row);
}
}
return dt;
}