QI继承了对MSSql的几个存储过程调用。这个包含几个连接。我的问题是:在这种情况下使用L2E会比通过ADO直接调用存储过程更快吗?这是我的LinQ查询:
public List<object> getDNISData(int DNIS)
{
List<object> DataItems = new List<object>();
using (VPEntities VPCtx = new VPEntities())
{
var DD =
from nm in VPCtx.NumberMaps
join g in VPCtx.Greetings on nm.Greeting_ID equals g.Greeting_ID
join p1 in VPCtx.Prompts on nm.Prompt1_ID equals p1.Prompt_ID
join p2 in VPCtx.Prompts on nm.Prompt2_ID equals p2.Prompt_ID
join p3 in VPCtx.Prompts on nm.Prompt3_ID equals p3.Prompt_ID
join p4 in VPCtx.Prompts on nm.Prompt4_ID equals p4.Prompt_ID
join p5 in VPCtx.Prompts on nm.Prompt5_ID equals p5.Prompt_ID
join h1 in VPCtx.HoldMsgs on nm.HoldMsg1_ID equals h1.HoldMsg_ID
join h2 in VPCtx.HoldMsgs on nm.HoldMsg2_ID equals h2.HoldMsg_ID
join hm in VPCtx.HoldMusics on nm.HoldMusic_ID equals hm.HoldMusic_ID
join d in VPCtx.Disclaimers on nm.Disclaimer_ID equals d.Disclaimer_ID
where nm.DNIS == DNIS && nm.Enabled
select (new {NumberID = nm.Number_ID, PortfolioID = nm.Portfolio_ID, PropertyID = nm.Property_ID, Adsource = nm.AdSource_ID,
PlanTypeID = nm.PlanType_ID, GreetingFile = g.GreetingFile,
PromptFile1 = p1.PromptFile, Accepts1 = p1.Accepts, PromptAction_ID1 = p1.PromptAction_ID,
PromptFile2 = p2.PromptFile, Accepts2 = p2.Accepts, PromptAction_ID2 = p2.PromptAction_ID,
PromptFile3 = p3.PromptFile, Accepts3 = p3.Accepts, PromptAction_ID3 = p3.PromptAction_ID,
PromptFile4 = p4.PromptFile, Accepts4 = p4.Accepts, PromptAction_ID4 = p4.PromptAction_ID,
PromptFile5 = p5.PromptFile, Accepts5 = p5.Accepts, PromptAction_ID5 = p5.PromptAction_ID,
HoldMsgFile1 = h1.HoldMsgFile, HoldMsgFile2 = h2.HoldMsgFile,
Destination1 = nm.Destination1, Destination2 = nm.Destination2, Destination3 = nm.Destination3,
UIType_ID = nm.UIType_ID,
RingCount = nm.RingCount,
Enabled = nm.Enabled,
Spanish = nm.Spanish,
HoldMusicFile = hm.HoldMusicFile,
Template_ID = nm.Template_ID,
FrontLineForward = nm.FrontLineForward,
DisclaimerFIle = d.DisclaimerFile});
DataItems = DD.ToList<object>();
return DataItems;
};
}
答案 0 :(得分:0)
如果LINQ查询存在包含在存储过程中的SQL查询的直接转换,则调用存储过程可能会稍微快一些 - 不是因为它会影响数据库的性能,而是因为LINQ to Entities必须先将您的查询翻译成SQL。
无论数据大小如何,转换的成本都是相同的,因此,如果查询在数据库上运行得非常快,那么差异可能会很明显,但是你要调用它很多,多次。在您发现性能存在问题之前,我建议您做一些最容易维护的代码。