Which is faster linq or sql




















How is this achieved? This code produces zero extra allocations and zero type casts while reading query results. That is where LINQ advantage comes from — it is aware of resulting data types and can generate specialized deserialization code, while regular SQL query reads all field values as objects, which causes excessive allocations IList for each row, boxing of value types and requires type casting.

Published at DZone with permission of Pavel Tupitsyn. See the original article here. Performance Zone. Thanks for visiting DZone today,. Edit Profile. So - there really isn't any "best" approach to the situation and the two can be used interchangably. Your performance will be related to how much data you are inserting, the amount of data currently in your table and the indexes you are maintaining.

I have had situations where adding an index and rebuilding a table has taken insert time down from minutes to milliseconds, just due to bad fragmentation and lack of an algorithm. Linq is an effective way to generate SQL for insertion and modification logic. However you will always end up with the pattern:. If you have any logic you can exploit in your insertions, you may be able to use set logic to do updates in SQL.

However as gbn has already correctly pointed out, unless you have a team full of strong SQL coders, maintenance will often trump any perf gain in the short term. These APIs will use smarter algorithms and perform any constraint checks in batches rather than per insert which will give you excellent performance increases. But managing an SSIS package is far more work than clicking a button in an app. These are all design decisions you will need to consider when you architect your application.

Because of how some of the abstractions translate, some tasks are far more suited to be done in a stored sproc or ado. If LINQ isn't performing, you can attempt to tune, in the sameway, just because SQL isn't performing doesn't mean sql wasn't a good choice, it just means it needs to be tuned.

I know that SQL is absolutely faster, but I would know Your performance will be related to how much data you are inserting, the amount of data currently in your table and the indexes you are maintaining. I have had situations where adding an index and rebuilding a table has taken insert time down from minutes to milliseconds, just due to bad fragmentation and lack of an algorithm.

Linq is an effective way to generate SQL for insertion and modification logic. However you will always end up with the pattern:. If you have any logic you can exploit in your insertions, you may be able to use set logic to do updates in SQL.

However as gbn has already correctly pointed out, unless you have a team full of strong SQL coders, maintenance will often trump any perf gain in the short term. These APIs will use smarter algorithms and perform any constraint checks in batches rather than per insert which will give you excellent performance increases. But managing an SSIS package is far more work than clicking a button in an app.

These are all design decisions you will need to consider when you architect your application. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 9 years ago.



0コメント

  • 1000 / 1000