Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 2 queries that it stuck and never finish Can anybody help me? I am trying to avoid a foreach and because of this I want to use the linked queries
I want ret1 search for all the data in q1

Thanks in advance

var q1 = Filter.Number.Select(item => new
                {
                    NH = item.Substring(0, 11),
                    NVH = item.Substring(14, 2),
                    NS = item.Substring(19, 11),
                    NVS = item.Substring(33),
                }).AsQueryable();

ret1 = (from v in VE
        where q1.Select(q=> q.NH).Contains(v.NH) &&
              q1.Select(q => q.NVH).Contains(v.NVH) &&
              q1.Select(q => q.NS).Contains(v.NS) &&
              q1.Select(q => q.NVS).Contains(v.NVS) 
        join deal in VDA
            on v.NIV equals deal.NIV
        where deal.time >= Filter.From && deal.time <= Filter.To &&
        deal.ModelCode == mdlCode
        let ccc = CT.FirstOrDefault(c => c.Ticket == v.SMF || c.Ticket == deal.SM)
        join list in LM on ccc.Mar equals list.MarE
        select new ReportData
                {
                    NIV = v.NIV,
                    AC = v.AC,
                    ID = v.NH + " - " + v.NVH + " - " + v.NS + " - " + v.NVS,
                    Date = deal.time,
                    UserId = ccc.UserId,
                    MAR = list.Name,
                    XX = ccc.x
                }).AsQueryable();
ret = ret1.Where(nr =>
    Filter.Mar == null || !Filter.Mar.Any() || Filter.Mar.Contains(nr.Mar)
).ToList();
Posted
Comments
Abhipal Singh 23-Jul-15 11:49am    
Can you let us know, what are you trying to achieve by the above query?
Merely saying 'it stuck' is not helping :)

Can you refine your question by providing sample input data and expected output.
Lalyka 24-Jul-15 12:11pm    
I have attached a picture here
https://dba.stackexchange.com/questions/108016/linq-query-optimization
I would be so thankful if any body can help me there
Abhipal Singh 25-Jul-15 1:21am    
The execution plan clearly shows that the joins are making the query slow.
Unless, you don't provide some clear information on what you are trying to achieve? it will be very difficult to solve the issue.
Also, provide some insight on the size of the data(no of rows, etc) in the participating tables(on which joins are applied).
May be, creating indexes on those tables will make the query run faster.

You can also try to run the query in pieces to see which join is stalling the query.

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