【发布时间】:2014-04-24 09:01:45
【问题描述】:
当我从以下查询中调用“api/test/name=stop,tap,app...(24 个名称值)”时,我遇到了错误:
"Message":"An error has occurred.","ExceptionMessage":"Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.","ExceptionType":"System.Data.SqlClient.SqlException
Linq 查询:
var data = db.database_bd.AsQueryable();
if (query.startDate != null)
{
data = data.Where(c => c.UploadDate >= query.startDate);
}
// If any other filters are specified, return records which match any of them:
var filteredData = new List<IQueryable<database_bd>>();
if (!string.IsNullOrEmpty(query.name))
{
var ids = query.name.Split(',');
foreach (string i in ids)
{
filteredData.Add(data.Where(c => c.Name != null && c.Name.Contains(i)));
}
}
// If no filters passed, return all data.
// Otherwise, combine the individual filters using the Union method
// to return all records which match at least one filter.
if (filteredData.Count != 0)
{
data = filteredData.Aggregate(Queryable.Union);
}
if (!data.Any()) //line causing error
{
var message = string.Format("No data was found");
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
}
return Request.CreateResponse(HttpStatusCode.OK, data);
}
查询类:
public class Query
{
public string name { get; set; }
public Nullable<DateTime> startDate { get; set; }
public Nullable<DateTime> endDate { get; set; }
}
我尝试在“filterdata”方法中添加一个范围,但我无法让它工作。任何建议,将不胜感激。
谢谢
【问题讨论】:
-
所以您希望数据与 firstFilter (startDate) 或数据与其他过滤器 (query.name) 相结合?
-
我希望能够使用 (name) 参数调用 (startDate),但如果可能的话,能够过滤许多 (name) 参数值 (1-70)。所以回答 - 与其他过滤器(query.name)相结合的数据。感谢您的回复。
标签: c# linq entity-framework asp.net-web-api