【发布时间】:2016-03-17 09:03:49
【问题描述】:
由于复杂的数据关系,我有多个表连接的查询, 为了优化查询,所以我设置了 linq ObjectTrackingEnabled 为 false,然后构建查询并加入我自己。
var tempapp = (
from app in CTX.user_applications
join user in CTX.user_lists on app.user_id equals user.user_id
join pst in CTX.postings on app.posting_id equals pst.posting_id
join job in CTX.job_ms on pst.job_id equals job.job_id
join loc in CTX.job_location_ms on pst.location_id equals loc.job_location_id
join jobcat in CTX.job_category_ms on pst.job_cat_id equals jobcat.job_category_id
join offcat in CTX.office_category_ms on pst.office_cat_id equals offcat.office_category_id
from appstat in CTX.app_status_ms.Where(stat => stat.app_status_id == app.app_status_id).DefaultIfEmpty()
from address in CTX.user_addresses.Where(addr => addr.user_id == user.user_id && addr.address_type == 0).DefaultIfEmpty()
from state in CTX.state_ms.Where(st => st.state_id == address.state_id).DefaultIfEmpty()
from edu in CTX.user_edus.Where(ed => ed.user_id == user.user_id).DefaultIfEmpty()
select new CustomObj
{
application_id = app.user_app_id,
job_cat_id = jobcat.job_category_id,
job_cat_desc = jobcat.PSF_Desc,
off_cat_id = offcat.office_category_id,
off_cat_desc = offcat.PSF_Desc,
loc_id = loc.job_location_id,
loc_desc = loc.PSF_Desc,
job_id = job.job_id,
job_desc = job.PSF_Desc,
state_id = state.state_id,
state_desc = state.state_desc,
edu_lvl_id = edu.edu_lvl_id,
applied_date = app.applied_date,
manager_id = app.manager_id,
gender_id = user.gender_id,
birthdate = user.birthday,
status_web = app.status_web,
status_psf = appstat.status_web,
user_id = user.user_id,
app_status_id = app.app_status_id,
online_test_id = app.online_test_id
}
).ToList();
我不知道为什么,但是这个查询抛出了超时错误:
超时。在完成之前超时时间已过 操作或服务器没有响应。
有人可以指点我来解决这个问题吗?
【问题讨论】:
-
如果请求超过 30 秒,Linq 将停止。设置DataContext.CommandTimeout 来避免这种情况
-
@Nitro.de 谢谢,我会试一试。
标签: c# asp.net sql-server linq