user3002167
user3002167

Reputation: 45

LINQ is so slow with huge database table

I have an ASP.Net MVC software with SQL server backend. I have a table with 80 column, currently counting about 975413 records. I am using Linq for the transactions with database. The problem is that I noticed that it is taking so long time to execute commands like SaveChanges(), Find(), Select().. and so.

How can I reduce the time taken to execute such Linq commands...

Upvotes: 2

Views: 698

Answers (1)

McGarnagle
McGarnagle

Reputation: 102793

You'll have to do some profiling.

  1. Log the actual SQL commands that Linq is generating.
  2. Use SQL Server profiling to suss out which queries are the worst culprits in terms of performance. Examine those queries' execution strategies.

If Linq is generating silly SQL, then you might have to tweak your Linq code, or consider using raw SQL commands. If the execution strategies are showing unwanted strategies like table scans, then you might want to consider adding indices, or changing them (re-ordering the keys, adding included columns).

Note also that Linq is generally quite slow. But really, 1 million records isn't that big, I'm sure you can improve performance using the above.

Upvotes: 4

Related Questions