Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

C#
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:
C#
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.
Posted
Updated 28-Apr-14 23:26pm
v2
Comments
Sampath Lokuge 25-Apr-14 6:05am    
Can you put the sql query which you ran on your db ?
miss786 25-Apr-14 6:20am    
select *
from [dbo].[database_BD]
where TAG like '%78473TAC4%'
or TAG LIKE '%05946XYZ0%'
OR NAME LIKE '%TAP%'
OR NAME LIKE '%STORM%'


Many thanks for your response and feedback.

1 solution

C#
var yourList = declare-your-list

 if (!string.IsNullOrEmpty(query.name))
            {

                var lists = query.name.split(',');

                foreach(var l in lists)
                {

                if (data.Where(pr => pr.Name.Contains(l)) !=null)
                      {
                       yourList.AddRange(data.Where(pr => pr.Name.Contains(l)));
                      }

                }

           }


Above I have showed how to do it for the one part of your code snippet.So try the same for other parts and add it into yourList List and get finally filtered list.I hope this will help to you.If you have further issues,Please ask. :)
 
Share this answer
 
Comments
Sampath Lokuge 29-Apr-14 5:43am    
Please check this one.http://stackoverflow.com/questions/14163390/some-part-of-your-sql-statement-is-nested-too-deeply-rewrite-the-query-or-break

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900