很抱歉这样一般的问题..我正在使用Entity& LINQ查询名为Patient.
的表(Model)我的目标是使用JqueryUI的自动完成来协助ASP.Net MVC 5建议的搜索文本栏,您可以在其中使用字符串作为患者姓名,但也可以使用其中的键。同一个盒子。这是我的模型:
public partial class Patient
{
public Patient()
{
PickupExchange = new HashSet<PickupExchange>();
SalesOrder2 = new HashSet<SalesOrder2>();
}
public int PtKey { get; set; }
public int? PatientId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string BillingAddress1 { get; set; }
public string BillingAddress2 { get; set; }
public string BillingCity { get; set; }
public string BillingState { get; set; }
public string BillingZip { get; set; }
public string BillingPhone { get; set; }
public string Faxnumber { get; set; }
public string EmailAddress { get; set; }
public string MobilePhone { get; set; }
public string Suffix { get; set; }
public DateTime? Dob { get; set; }
public string Ssn { get; set; }
public string HoldAcct { get; set; }
public string AccountNumber { get; set; }
public string AccountGrp { get; set; }
public string Sex { get; set; }
public decimal? Height { get; set; }
public decimal? Weight { get; set; }
public string MaritalStatus { get; set; }
public string Employment { get; set; }
public byte? DiscountPct { get; set; }
public byte? BranchKey { get; set; }
public string DelivAddress1 { get; set; }
public string DelivAddress2 { get; set; }
public string DelivCity { get; set; }
public string DelivState { get; set; }
public string DelivZip { get; set; }
public string DelivPhone { get; set; }
public string User1 { get; set; }
public string User2 { get; set; }
public string User3 { get; set; }
public string User4 { get; set; }
public string EclastName { get; set; }
public string EcfirstName { get; set; }
public string EcmiddleName { get; set; }
public string Ecaddress1 { get; set; }
public string Ecaddress2 { get; set; }
public string Eccity { get; set; }
public string Ecstate { get; set; }
public string EcpostalCode { get; set; }
public string EcphoneNum { get; set; }
public string Ecfax { get; set; }
public string Ecemail { get; set; }
public string Rprelationship { get; set; }
public string RplastName { get; set; }
public string RpfirstName { get; set; }
public string RpmiddleName { get; set; }
public string Rpaddress1 { get; set; }
public string Rpaddress2 { get; set; }
public string Rpcity { get; set; }
public string Rpstate { get; set; }
public string RppostalCode { get; set; }
public string RpphoneNum { get; set; }
public string Rpfax { get; set; }
public string Rpemail { get; set; }
public string HippasignatureOnFile { get; set; }
public string TaxZone { get; set; }
public string BillingCounty { get; set; }
public string DeliveryCounty { get; set; }
public int? ReferralKey { get; set; }
public string ReferralType { get; set; }
public short? CreatedBy { get; set; }
public DateTime? CreateDt { get; set; }
public string NickName { get; set; }
public string AutoChargeCc { get; set; }
public string SarautoPayStatus { get; set; }
public string SareDeliveryStatus { get; set; }
public string SarpaymentPlan { get; set; }
public string Sarinformation { get; set; }
public DateTime UpdateDt { get; set; }
public DateTime? Dod { get; set; }
}
问题是我的SQL表中包含的所有患者数据绝对是巨大的。我正在使用我的LINQ查询将一个TOP 10作为json返回到我的javasript函数:
var alreadyRunning = false;
patientID.bind('input', function () {
if (alreadyRunning == false) {
alreadyRunning = true;
$.ajax({
type: 'POST',
url: '/Controller/Model',
dataType: 'json',
data: {
patientID: patientID.val()
},
success(data) {
patientID.autocomplete({
source: data
});
alreadyRunning = false;
}
, failure(data) {
alert("Error Searching Value: " + patientID.val());
alreadyRunning = false;
}
, error(data) {
alert("Error Searching Value: " + patientID.val());
alreadyRunning = false;
}
});
}
else {
patientID.autocomplete({
source: ["None"]
});
}
这个LINQ查询保持超时,我找不到加速查询的方法..我做错了什么或我的数据集太大了?
ptTable = int.TryParse(patientID, out number) ?
btd.Patient.Where(x => x.Database == "databaseName" && x.PatientId.ToString().StartsWith(number.ToString())).OrderBy(x => x.LastName).Take(10).ToList() :
btd.Patient.Where(x => x.Database == "databaseName" && x.LastName.ToLower() + ", " + x.FirstName.ToLower()).StartsWith(patientID.ToLower()).OrderBy(x => x.LastName).Take(10).ToList();
对SQL执行快速执行的字符串操作是否过多?任何建议都会非常有益!