Reputation: 4848
Okay, here's a dumb question.
As I understand it, a SQL View is a virtual table based on the result-set of a SQL query.
From my limited knowledge of a SQL View, I'm assuming that a result set that I get from a LINQ statement is the same thing as a SQL View.
Am I mistaken?
The reason I'm asking is that I have a program that is using a foreach
loop to read over a result-set from a LINQ query, row by row. A co-worker said I should use a pre-built SQL View to speed up the program. Not being familiar with SQL Views, I'm not sure how it would help me, based on my limited knowledge.
Upvotes: 3
Views: 478
Reputation: 1570
You might look to SQL views as a result set, that may combine the values of multiple tables (by joining, using sub-select's etc.). If you query a SQL view, you get better performance.
Linq 2 SQL returns you set of data and does a mapping to an object, so you get IList.
Linq works with so called IQueryable interface. The benefit is that IQueryable is executed when you hit iq.List(), iq.Array() method on the IQueryable expression.
I actually used it in one of my project in a special way: - created the desired IQueryable query - then depending on the use-case I've executed iq.Count() or iq.List() on it. Since I could avoid calint iq.List() (and since I mostly needed only to know the count) I got perf. increase - and I didn't had to modify existing code considerably.
Upvotes: 2