Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ version of SQL View?

Tags:

c#

linq

sql-view

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.

like image 758
Kevin Avatar asked Jan 23 '26 20:01

Kevin


1 Answers

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.

like image 139
baHI Avatar answered Jan 26 '26 12:01

baHI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!