我必须根据来自azure SQL服务器的多表上的类似条件选择值列表。当我尝试从数据库中搜索值时。我在执行过程中收到以下错误。
超时已过期。在完成之前经过了超时时间 操作或服务器没有响应。声明一直如此 终止
private IQueryable<UserProfile> UserProfileDetailsConditionalQuery(string query, bool? isActive)
{
try
{
DateTime dateInput;
bool isDate = DateTime.TryParse(query, out dateInput);
return from ub in idamDbContext.UserBasicInfo
join ur in idamDbContext.UserRoles on ub.UserId equals ur.UserBasicInfoId
join rl in idamDbContext.Role on ur.RoleId equals rl.Id
join t in idamDbContext.Territory on ub.TerritoryId equals t.Id
into territory
from leftTerritory in territory.DefaultIfEmpty()
where (ub.FirstName.ToUpper().Contains(query.ToUpper())
|| ub.LastName.ToUpper().Contains(query.ToUpper())
|| ub.Email.ToUpper().Contains(query.ToUpper())
|| rl.Description.ToUpper().Contains(query.ToUpper())
|| leftTerritory.Name.ToUpper().Contains(query.ToUpper())
|| (isDate && ub.Created.Value.Date.Equals(query)))
&& ((isActive != null) ? ub.IsActive == isActive : (ub.IsActive == true || ub.IsActive == false))
orderby ub.Created descending, rl.Created descending
select new UserProfile()
{
UserId = ub.UserId,
FirstName = ub.FirstName,
LastName = ub.LastName,
EmailId = ub.Email,
UserRole = (from r in idamDbContext.Role
where r.Id == ur.RoleId
select rl.Description).ToList(),
TerritoryName = leftTerritory != null ? leftTerritory.Name : null,
CreatedDate = ub.Created.HasValue ? ub.Created.Value.ToString("dd/MM/yyyy") : string.Empty,
IsActive = ub.IsActive.HasValue ? ub.IsActive : null
};
}
catch (Exception ex)
{
throw ex;
}
}
注意: - 当我在SQL服务器中执行相同的查询时,它会正常工作但LINQ我会收到超时错误或对象引用错误。
通常,在查询上传递的更多值作为搜索参数(如TerritoryName,role),如果存在则会返回一些值但是当我将名字和姓氏作为搜索参数传递时,没有数据即使数据库中存在记录,也会返回。
我不知道这是怎么发生的,从数据库获取所有这些数据(近144000条记录)的方法是正确的。请分享您的观点以解决问题。