In my asp.net mvc 2 app I have an action which is rather data-heavy. I'm using linq-to-sql for the queries, while using the repository pattern. When I check the execution of the action in SQL Server profiler, I find that approximately 60 queries are bein开发者_运维技巧g executed. My question is - and I hope there is enough infomation in the question to answer it - does asp.net mvc make a full round trip, back and fourth, to the database, for each and every query, or is it that because of the use of linq, there is actually only one round trip ?
I believe it's one round trip per query, whether that is a LINQ query or raw SQL. I suppose it depends on what you mean by "each and every query."
To answer your comment above:
var result = LINQ; <--- Query is generated, but not executed
foreach( YourDataType ydt in result ) { <--- Query executes when you do something with result
...
}
It depends on what your Linq looks like. It's my understanding that when your result set enumerates you will hit the database.
精彩评论