开发者

Effective use of LINQ2SQL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I am a LINQ2SQL fan, however, EF is also coming along. In my web application project I created various LINQ2SQL queries in different functions. Like:

Function A()
{
// LINQ2SQL QueryA accessing Database ABC
}
Function B()
{
// LINQ2SQL QueryB accessing Database ABC
}
Function C()
{
// LINQ2SQL QueryC accessing Database ABC
}
Function D()
{
// LINQ2SQL QueryD accessing Database ABC
}
Function E()
{
// LINQ2SQL QueryE a开发者_JAVA百科ccessing Database ABC
}

As you can see, my app is not efficient at all. I want to make this efficient by querying my DB only once and then fetching from it in different functions. What should be the better implementation for this?

Thanks!


You will need to keep the same context throughout the lifetime of your webrequest. Using the same context, will allow you to benifit from the cache. It will also allow you to save the time required to build the context on each request throughout the lifetime of your webrequest.

You will also need to load the data using eager loading.

ei. eager loading, is loading data using the "Include()" method. this will load all specified related data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜