简体   繁体   中英

LINQ to Entities (The wait operation timed out)

I would like to find a help here with one query. I'm using Entity Framework and SQL DB in my ASP.NET MVC project. There are records from molding machine. Every record has name like "156812 NameOfParameter" where the number is molding machine production number and name is a name of parameter, value and date . A group of records with the same date is created every cycle of molding machine. But there haven't to be all the parameters in the group of records. This mean that value of missing parameter is same like value of first record with older date and name like "%NameOfParameter"

My goal is to crate list of Molding machine cycles. It means list of parameters with the same date and time (without milisecunds) and fill up all missing values.

Dataset from the database for specific molding machine and date from -> to

var lisData = GetSet().Where(t => t.Name.Contains(cisloLisu));
            if (request.DateFrom.HasValue && request.DateTo.HasValue)
            lisData= lisData.Where(t => t.SampleDateTime >= request.DateFrom.Value && t.SampleDateTime <= request.DateTo.Value);

1) Grouping by date and time (without milisecunde)

            var set =
            from tag in lisData
            group tag by DbFunctions.CreateDateTime(
                tag.SampleDateTime.Year,
                tag.SampleDateTime.Month,
                tag.SampleDateTime.Day,
                tag.SampleDateTime.Hour,
                tag.SampleDateTime.Minute,
                tag.SampleDateTime.Second)
            into zdvih
            select zdvih;

Now i have IQueryble<IGrouping<DateTime?, HistDataView>> object.

2) From this object i need to do List of molding cycles

      var set2 =
            from zdvih in set
            let wz = 
                zdvih.FirstOrDefault(t => t.Name.Contains("Cislo nastroje")) ??
                lisData.FirstOrDefault(t => t.SampleDateTime < zdvih.Key && t.Name.Contains("Cislo nastroje"))
            let snr =
                zdvih.FirstOrDefault(t => t.Name.Contains("Cislo dilu")) ??
                lisData.FirstOrDefault(t => t.SampleDateTime < zdvih.Key && t.Name.Contains("Cislo dilu"))               
            select new ZdvihView()
            {
                Datum = zdvih.Key,
                CisloNastroje = wz.Value,
                CisloDilu = snr.Value,
            };

Problem is that i dont know why it take so much time. Even if i look only for last hour. I almost always get error "The wait operation timed out"

Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

Thanks for every help

Use default SQL Server profiler to watch the translated and executed TSQL queries. It's possible the translated TSQL query take too much time to execute. if not use linq profiler like Linq Insight to analyze your query and find the bottleneck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM