Skip to main content
tag tidy
Link
Marc Gravell
  • 1.1m
  • 273
  • 2.6k
  • 3k
Bounty Ended with David Yancey's answer chosen by Nathan Ridley
added 187 characters in body
Source Link
Nathan Ridley
  • 34.5k
  • 35
  • 131
  • 205

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance.

Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation?

UPDATE

I ended up using a dodgy hack which did the trick. I know that there will ALWAYS be at least one user in the user table, so I ended up using:

var data = (from tmp in DataContext.Users select new { Property1 = (from...), Property2 = (from...), PropertyN = (from...), }).First(); 

UPDATE 2

It has been implied in one of the answers that doing this may create MARS (Multiple Active Result Set) errors. What are these errors (I have never seen one), why do they occur and is there anything wrong the whole premise of this line of questioning? i.e. Am I flawed in my assertion that asking the database to return everything in one go is going to be quicker/more efficient than doing fourteen wholly separate LINQ queries?

UPDATE 3

I think my approach is redundant and from a pragmatic perspective, should be handled differently, either via a stored procedure or some sort of delayed/mixed approach.

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance.

Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation?

UPDATE

I ended up using a dodgy hack which did the trick. I know that there will ALWAYS be at least one user in the user table, so I ended up using:

var data = (from tmp in DataContext.Users select new { Property1 = (from...), Property2 = (from...), PropertyN = (from...), }).First(); 

UPDATE 2

It has been implied in one of the answers that doing this may create MARS (Multiple Active Result Set) errors. What are these errors (I have never seen one), why do they occur and is there anything wrong the whole premise of this line of questioning? i.e. Am I flawed in my assertion that asking the database to return everything in one go is going to be quicker/more efficient than doing fourteen wholly separate LINQ queries?

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance.

Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation?

UPDATE

I ended up using a dodgy hack which did the trick. I know that there will ALWAYS be at least one user in the user table, so I ended up using:

var data = (from tmp in DataContext.Users select new { Property1 = (from...), Property2 = (from...), PropertyN = (from...), }).First(); 

UPDATE 2

It has been implied in one of the answers that doing this may create MARS (Multiple Active Result Set) errors. What are these errors (I have never seen one), why do they occur and is there anything wrong the whole premise of this line of questioning? i.e. Am I flawed in my assertion that asking the database to return everything in one go is going to be quicker/more efficient than doing fourteen wholly separate LINQ queries?

UPDATE 3

I think my approach is redundant and from a pragmatic perspective, should be handled differently, either via a stored procedure or some sort of delayed/mixed approach.

Bounty Started worth 100 reputation by Nathan Ridley
added 445 characters in body
Source Link
Nathan Ridley
  • 34.5k
  • 35
  • 131
  • 205

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance.

Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation?

UPDATE

I ended up using a dodgy hack which did the trick. I know that there will ALWAYS be at least one user in the user table, so I ended up using:

var data = (from tmp in DataContext.Users select new { Property1 = (from...), Property2 = (from...), PropertyN = (from...), }).First(); 

UPDATE 2

It has been implied in one of the answers that doing this may create MARS (Multiple Active Result Set) errors. What are these errors (I have never seen one), why do they occur and is there anything wrong the whole premise of this line of questioning? i.e. Am I flawed in my assertion that asking the database to return everything in one go is going to be quicker/more efficient than doing fourteen wholly separate LINQ queries?

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance.

Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation?

UPDATE

I ended up using a dodgy hack which did the trick. I know that there will ALWAYS be at least one user in the user table, so I ended up using:

var data = (from tmp in DataContext.Users select new { Property1 = (from...), Property2 = (from...), PropertyN = (from...), }).First(); 

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance.

Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation?

UPDATE

I ended up using a dodgy hack which did the trick. I know that there will ALWAYS be at least one user in the user table, so I ended up using:

var data = (from tmp in DataContext.Users select new { Property1 = (from...), Property2 = (from...), PropertyN = (from...), }).First(); 

UPDATE 2

It has been implied in one of the answers that doing this may create MARS (Multiple Active Result Set) errors. What are these errors (I have never seen one), why do they occur and is there anything wrong the whole premise of this line of questioning? i.e. Am I flawed in my assertion that asking the database to return everything in one go is going to be quicker/more efficient than doing fourteen wholly separate LINQ queries?

added 401 characters in body
Source Link
Nathan Ridley
  • 34.5k
  • 35
  • 131
  • 205
Loading
Source Link
Nathan Ridley
  • 34.5k
  • 35
  • 131
  • 205
Loading