我想调用下面的查询字符串,但我在客户端收到'无数据'消息 - 'api/data?id = 786,899 & price_type = cvr'。如何在linq查询中使用split?
public HttpResponseMessage Get([FromUri] Query query)
{
var data = db.database_ICs.AsQueryable();
if (query.id!= null)
{
data = data.Where(c => query.id.Split(',').Contains(c.ID));
}
if (query.price_type != null)
{
data = data.Where(c => c.Cover == query.price_type);
}
if (!data.Any())
{
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 id{ get; set; }
public string price_type { get; set; }
public Nullable<DateTime> startDate { get; set; }
public Nullable<DateTime> endDate{ get; set; }
}
任何帮助将非常感激。 非常感谢。
是'c.ID'类型的字符串? – okrumnow
这是'LINQ to SQL'吗? “LINQ to SQL”没有将'string.Split'转换为SQL。 –
hi @okrumnow,是的,这是正确的。 – user3070072