如何在linq中查询多个'Split'?

时间:2014-01-13 14:58:50

标签: asp.net-mvc linq entity-framework linq-to-sql asp.net-web-api

我正在尝试从下面的代码执行以下调用(“api / test / sin = 2129VAH99,8974922& sip = 108124AG3”),但我似乎无法接到调用工作,因为它一直响应'无数据'错误。

 public HttpResponseMessage Get([FromUri] Query query)
    {
        var data = db.database_Items.AsQueryable();

        if (!String.IsNullOrEmpty(query.sip))
        {
            var ids = query.sip.Split(',').ToList();

            data = data.Where(c => ids.Any(i => (c.SIP != null && c.SIP.Contains(i))));
        }

        if (!String.IsNullOrEmpty(query.sin))
        {
            var ids = query.sin.Split(',').ToList();

            data = data.Where(c => ids.Any(i => (c.SINs != null && c.SINs.Contains(i))));
        }


        if (!data.Any())
        {

            return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
        }

        return Request.CreateResponse(HttpStatusCode.OK, data);
    }

非常感谢任何帮助/指导。非常感谢。

1 个答案:

答案 0 :(得分:0)

尝试将您的网址更改为:

API /测试罪= 2129VAH99,8974922&安培;啜饮= 108124AG3