本文介绍了如何使用linq搜索多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



当我尝试查询时(/ api / data?name = storm,prestl,bcam& tag = 78473TAC4,12669VAC2,05946XYZ0)。

我收到(没有数据)回复。我已经测试了查询及其对我的sql的值,并能够输出10条记录。



  var  data = db.database_Bd.AsQueryable(); 
if (query.startDate!= null
{
data = data.Where(c = > c.UploadDate > = query.startDate);
}

if (!string.IsNullOrEmpty(query.name))
{
var list = query.name.split(' ,');
data = data.Where(pr = > list.Any(pr2 = > pr.Name.Contains(PR2)));
}

if (!string.IsNullOrEmpty(query.tag))
{
var list = query.tag.split(' ,');
data = data.Where(pr = > list.Any(pr2 = > pr.TAG.Contains(PR2)));
}





以下更新代码:

  var  filteredData =  new 列表< IQueryable< database_bd>>(); 

if (!string.IsNullOrEmpty(query.tag))
{
var ids = query.tag.Split(' ,');
foreach string i in ids)
{
var list = data.Where(c = > c.TAG!= null && c.TAG.Contains(i))。AsQueryable();

filteredData.Add(list);
}
}

if (filteredData.Count!= 0
{
data = filteredData.Aggregate(Queryable.Union);
}





我遇到错误 (ExceptionMessage:部分内容您的SQL语句嵌套得太深了。重写查询或将其分解为较小的查询。)当我运行查询时如下:



api / test?tag = 78473,12669,05946,

45660,02150,12667,4566,3622,38379,

61755,45660,3384,288,23242,81378 ,

68402,59025,59024,59024,59023,12669,

76111,86359,05946,05946

01448,07387,14889, 22545,3136,38137,49638





请帮忙。如果可能的话,非常感谢任何建议。

解决方案

Dear all,

When I try to query(/api/data?name=storm,prestl,bcam&tag=78473TAC4,12669VAC2,05946XYZ0).
I am getting (no data) response. I have tested the query with its values against my sql and its able to output 10 records.

var data = db.database_Bd.AsQueryable();
        if (query.startDate != null)
        {
            data = data.Where(c => c.UploadDate >= query.startDate);
        }

        if (!string.IsNullOrEmpty(query.name))
        {
            var list = query.name.split(',');
            data = data.Where(pr => list.Any(pr2 => pr.Name.Contains(pr2)));
        }

        if (!string.IsNullOrEmpty(query.tag))
        {
            var list = query.tag.split(',');
            data = data.Where(pr => list.Any(pr2 => pr.TAG.Contains(pr2)));
        }



The following updated code:

var filteredData = new List<IQueryable<database_bd>>();

            if (!string.IsNullOrEmpty(query.tag))
            {
                var ids = query.tag.Split(',');
                foreach (string i in ids)
                {
                    var list = data.Where(c => c.TAG != null && c.TAG.Contains(i)).AsQueryable();

                    filteredData.Add(list);
                }
            }

            if (filteredData.Count != 0)
            {
              data = filteredData.Aggregate(Queryable.Union);
            }



I am experiencing an error (ExceptionMessage":"Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.) when I run a query such as:

api/test?tag = 78473,12669,05946,
45660,02150,12667,4566,3622,38379,
61755,45660,3384,288,23242,81378,
68402,59025,59024,59024,59023,12669,
76111,86359,05946,05946
01448,07387,14889,22545,3136,38137, 49638


Please help. Any advice, would be much appreciated, if possible.

解决方案


这篇关于如何使用linq搜索多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 15:29