Entity Framework - High Performance Querying Using Temp Tables
Today I came across a nice article explaining how we can optimize a query with multiple Include() of related entities. Usage of a temporary is nice, but the way it's created is not. There is absolutely no need to bring the Ids to the app server and then push them back to the database. The whole operation can be performed in the database using SELECT ... INTO construct:
static void PrepareStagingCategories(Product product) {
var temp = ToTable<Product>(TEMP_PRODUCT_IDS);
// create temporary table with product ids
SELECT<Product>(product.ProductId.@as()).INTO(temp);
FROM(product);
WHERE(product.Name.Contains("Chocolate"));
}
Comments
Post a Comment