I am using Entity Framework in my ASP.NET MVC application, and I am facing an issue in loading data from SQL Server via LINQ. My query returns the result in 4 seconds, but I need to get in less time, still searching for better solution.
Here is my linq query:
var user =
context.CreateObjectSet<DAL.ProductMaster>()
.AsNoTracking()
.Include("Product1").AsNoTracking()
.Include("Product2").AsNoTracking()
.Include("Product3").AsNoTracking()
.Include("Product4").AsNoTracking()
.Include("Product5").AsNoTracking()
.Where(x => x.Id == request.Id)
).FirstOrDefault();
Where()clause withFirstOrDefault()to clean things up a bit and you likely don't need theAsNoTracking()call for each individual Include()..Select()operator to grab exactly what you want, instead of this hodgepodge of what looks like a large proportion of your database.organizationsList.Count()!= 0(and, not performance-related: remove all but one AsNoTracking calls).