我遇到了一个问题,因为我正在尝试连接一个旧的第三方数据库并从中检索数据,该数据库使用现已弃用的文本字段。但是我无法更改数据库字段,因此当我尝试通过 LINQ 返回数据时会出现问题。下面的示例代码:
var query = from s in db.tSearches
join c in db.tCompanies on s.CompanyGUID equals c.GUID
join cl in db.tCompanyLocations on s.LocationGUID equals cl.GUID
join st in db.tSearchTypes on s.SearchTypeGUID equals st.GUID
where s.DateClosed == null
select new
{
Id = s.GUID,
Type = st.GUID,
Location = cl.LocationName,
Company = (s.Confidential) ? String.Empty : c.CompanyName,
DateOpened = s.DateOpened,
Notes = s.PlacementNotes,
Closed = s.DateClosed != null
};
在我最终尝试执行此操作之前,对此信息进行了更多过滤:
return query.Select(x => new VacancySummary
{
Id = x.Id,
Departments = "",
Location = x.Location,
Company = x.Company,
DateOpened = x.DateOpened,
Notes = x.Notes,
Closed = x.Closed
}).Distinct().Skip(skip).Take(take);
并得到上面的异常。我宁愿不必先执行整个 SQL 语句并在运行 Distinct 之前返回结果,因为如果每个用户检索每个搜索的所有记录,服务器带宽会降低性能,这就是为什么只有一部分返回数据。
有任何想法吗?