我正在开发一个将数据返回到 Windows Phone 应用程序的 REST 服务,并且查询的响应时间是一个考虑因素。目前的代码如下所示:
List<RestModels.Response.RealWorkOrder> RWOList = _context.MOB_WORKORDERS_SUMMARY
.Where(mws => _context.TBL_USER_GROUP_MEMBERS.Any(u => u.user_Id == UserID && u.user_Group_Id == mws.user_group_id))// && !disallowedStatuses.Contains(mws.workorder_status_id ?? -1))
.Select(mob => _context.FMIS_WORKORDER.FirstOrDefault(wo => wo.workorder_id == mob.workorder_id))
.Select(wo =>
new RestModels.Response.RealWorkOrder()
{
AssetLocation = wo.FMIS_ASSET_LOCATION.asset_location_description,
IAssets = wo.FMIS_WORKORDER_ASSETS.Select(woa => new RestModels.Subclasses.Asset()
{
AssetId = woa.FMIS_ASSET.asset_id,
AssetName = woa.FMIS_ASSET.asset_title + " - " + woa.FMIS_ASSET.asset_description,
SerialNumber = woa.FMIS_ASSET.asset_UF_1
}),
...
CategoryDescription = _context.VIEW_WORK_CATEGORIES.Where(cat => cat.work_category_id == wo.FMIS_WORKREQUEST1.FirstOrDefault().workrequest_category).FirstOrDefault().work_category_title + " - " +
_context.VIEW_WORK_CATEGORIES.Where(cat => cat.work_category_id == wo.FMIS_WORKREQUEST1.FirstOrDefault().workrequest_category).FirstOrDefault().work_category_description + " [" +
_context.VIEW_WORK_CATEGORIES.Where(cat => cat.work_category_id == wo.FMIS_WORKREQUEST1.FirstOrDefault().workrequest_category).FirstOrDefault().work_category_priority_name + "]",
我的问题与 CategoryDescription 字段有关——事实证明,连接非常昂贵。有没有办法对视图记录进行单一引用并即时连接字段?