LINQ query should not include your class projection to improve performance

Possibly save 1 hour of your time: I have found that performance of your LINQ query could be impact especially for large datasets when you project your results directly to a class object. It is better to project to .NET object after the sql query results came back first.

var results = (from a in context.TableA
                    join b in context.TableB on a.ID equals b.ID
                    select new YourClassName
                    {
                        Year = a.Year,
                        Name = b.Name
                    });
var list = results.ToList();

The code above is much slower than the code below for large datasets.

var results = (from a in context.TableA
                    join b in context.TableB on a.ID equals b.ID
                    select new
                    {
                        Year = a.Year,
                        Name = b.Name
                    });
var list = results.ToList();

var returnList = list.Select(x => new YourClassName
                {
                    Year = x.Year,
                    Name = x.Name
                }).ToList();

 

Advertisements

Request to run job refused because the job is already running from a request by user

Possibly save 1 hour of your time: I have a job that can take awhile to finish on development environment. I have started running the job and realize something I have missed. Now I want to stop or cancel the job, but I get this error telling me that the job is already running.

Solution: The easiest way is to restart the SQL Server Agent Service by going to SQL Server Configuration Manager or sqlservermanager11.msc in command prompt.