オブジェクトのパフォーマンスに問題がありSqlDataReader
ます。
私は Entity Framework の使用に慣れていますが、特定の理由から、アプリで ADO.NET クエリを使用する必要があります。
問題は、クエリを実行すると、ほぼ 10 秒かかることです。
SQL Server Management Studio でまったく同じクエリを実行すると、わずか 1 秒しかかかりません。
多分それだと思い、 aをaでSqlDataReader
埋めようとしましたが、同じ結果が得られました。DataTable
SqlDataAdapter
コードの何が問題になっていますか? のパフォーマンスを向上させる方法はありますSqlDataReader
か?
クエリと C# コードを次に示します。
string commandText = "SELECT Pati_FirstName, Pati_LastName, Pati_Gender AS Gender, "
+ " Pati_HeadQuarterID, Pati_AgencyID, Pati_Address1, Pati_Address2, Pati_BirthDate, Pati_FullName, Pati_FirstNameIfDiff, Pati_LastNameIfDiff, Pati_FootSize, Pati_ID, Pati_Height, Pati_MailAddress,"
+ " Pati_MobileNumber, Pati_PhoneNumber, Pati_PostCode, Pati_SecurityNumber, Pati_Weight,"
+ " Agen_Name, Head_Name, pat.Path_Name AS Pati_Pathologie,"
+ " gender.Capt_CulturInfo AS Pati_Gender, prof.Capt_CulturInfo AS Pati_Profession, title.Capt_CulturInfo AS Pati_Title, sport1.Capt_CulturInfo AS Pati_Sport1, sport2.Capt_CulturInfo AS Pati_Sport2,"
+ " p1.Pres_FullName AS Prescriber1, p2.Pres_FullName AS Prescriber2, pSender.Pres_FullName AS SentBy, Prac_FullName, City_Name"
+ " FROM Patient INNER JOIN HeadQuarter ON Head_ID = Pati_HeadQuarterID INNER JOIN"
+ " Agency ON Agen_ID = Pati_AgencyID LEFT OUTER JOIN"
+ " CustomCaption AS gender ON gender.Capt_Family = 'Pati_Gender' AND gender.Capt_Code = Pati_Gender LEFT OUTER JOIN"
+ " CustomCaption AS prof ON prof.Capt_Family = 'profession' AND prof.Capt_Code = Pati_Profession LEFT OUTER JOIN"
+ " Pathology AS pat ON pat.Path_ID = Pati_Pathologie LEFT OUTER JOIN"
+ " CustomCaption AS title ON title.Capt_Family = 'title' AND title.Capt_Code = Pati_Title LEFT OUTER JOIN"
+ " CustomCaption AS sport1 ON sport1.Capt_Family = 'sports' AND sport1.Capt_Code = Pati_Sport1 LEFT OUTER JOIN"
+ " CustomCaption AS sport2 ON sport2.Capt_Family = 'sports' AND sport2.Capt_Code = Pati_Sport2 LEFT OUTER JOIN"
+ " Prescriber AS p1 ON p1.Pres_ID = Pati_Doctor1 LEFT OUTER JOIN"
+ " Prescriber AS p2 ON p2.Pres_ID = Pati_Doctor2 LEFT OUTER JOIN"
+ " Prescriber AS pSender ON pSender.Pres_ID = Pati_SentBy LEFT OUTER JOIN"
+ " Practitioner ON Prac_ID = Pati_PracticionerID LEFT OUTER JOIN"
+ " City ON City_ID = Pati_CityID"
+ " WHERE Pati_Deleted IS NULL AND Pati_AgencyID = @AgencyID ORDER BY Pati_LastName, Pati_FirstName";
List<VPatient> retVal = new List<DataRepository.VPatient>();
try
{
using (SqlConnection sqlConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
{
using (SqlCommand sqlComm = new SqlCommand("", sqlConn))
{
sqlComm.CommandText = commandText.Replace("_CulturInfo", "_" + currentCultur);
sqlComm.Parameters.AddWithValue("@AgencyID", agencyID);
sqlComm.Connection.Open();
// This line takes 10 seconds.
SqlDataReader sqlRd = sqlComm.ExecuteReader();
// I tried this as an alternative, it doesn't change anything.
// SqlDataAdapter sqlAdp = new SqlDataAdapter(sqlComm);
// System.Data.DataTable dtPatients = new System.Data.DataTable();
// sqlAdp.Fill(dtPatients);
VPatient pat;
while (sqlRd.Read())
{
pat = new VPatient();
pat.Pati_HeadQuarterID = sqlRd["Pati_HeadQuarterID"].ToString();
pat.Pati_AgencyID = sqlRd["Pati_AgencyID"].ToString();
....
retVal.Add(pat);
}
}
}
}
catch (Exception ex)
{
CoreMethods.ParseError(ex, "GetPatientList");
}
また、SQL Server Management Studio で同じクエリを実行すると、わずか 1 秒しかかかりません。