I am using Linq to create 4 object collections:
var Restaurants = db.Places.Where(p => p.Tags.Any(t => t.Name == "Restaurant")).ToList();
var Bars = db.Places.Where(p => p.Tags.Any(t => t.Name == "Bar")).ToList();
var Pubs = db.Places.Where(p => p.Tags.Any(t => t.Name == "Pub")).ToList();
var Hotels = db.Places.Where(p => p.Tags.Any(t => t.Name == "Hotel")).ToList();
Obviously it's better to read once from the database, would the above open 4 connections with 4 queries on SQL Server 2012 or 1?
If I do the following instead, will Entity Framework only read from the database once, and what's the best way to test that myself?
var places = db.Places;
var Restaurants = places.Where(p => p.Tags.Any(t => t.Name == "Restaurant")).ToList();
var Bars = places.Where(p => p.Tags.Any(t => t.Name == "Bar")).ToList();
var Pubs = places.Where(p => p.Tags.Any(t => t.Name == "Pub")).ToList();
var Hotels = places.Where(p => p.Tags.Any(t => t.Name == "Hotel")).ToList();
What is Best Practice here? Are there any stats on this?
Thanks.