SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
Turn off ObjectTrackingEnabled Property of Data Context If Not Necessary
using (NorthwindDataContext context = new NorthwindDataContext())
{
context.ObjectTrackingEnabled = false;
}
- Do NOT Dump All Your DB Objects into One Single Data Context
- Use Compiled Query Wherever Needed
- Filter Data Down to What You Need Using DataLoadOptions.AssociateWith
- Turn Optimistic Concurrency Off Unless You Need It
- Constantly Monitor Queries Generated by the Data Context and Analyze the Data You Retrieve
- Avoid Unnecessary Attaches to Tables in the Context
- Be Careful of Entity Identity Management Overhead
- Retrieve Only the Number of Records You Need
- Do not Misuse Compiled Query
public static Func<Northwnd, string, IQueryable<Customer>>
CustomersByCity =
CompiledQuery.Compile((Northwnd db, string city) =>
from c in db.Customers where c.City == city select c);
public static Func<Northwnd, string, IQueryable<Customer>>
CustomersById = CompiledQuery.Compile((Northwnd db,
string id) => db.Customers.Where(c => c.CustomerID == id));
public IEnumerable<Customer> GetCustomersByCity(string city)
{
var myDb = GetNorthwind();
return Queries.CustomersByCity(myDb, city);
}
Reference:http://msdn.microsoft.com/en-us/library/system.data.linq.compiledquery.aspx
