dbset

DbSet.Find method ridiculously slow compared to .SingleOrDefault on ID

混江龙づ霸主 提交于 2019-11-27 03:34:35
I have the following code (Database is SQL Server Compact 4.0): Dim competitor=context.Competitors.Find(id) When I profile this the Find method takes 300+ms to retrieve the competitor from a table of just 60 records. When I change the code to: Dim competitor=context.Competitors.SingleOrDefault(function(c) c.ID=id) Then the competitor is found in just 3 ms. The Competitor class: Public Class Competitor Implements IEquatable(Of Competitor) Public Sub New() CompetitionSubscriptions = New List(Of CompetitionSubscription) OpponentMeetings = New List(Of Meeting) GUID = GUID.NewGuid End Sub Public

Can you get the DbContext from a DbSet?

安稳与你 提交于 2019-11-26 20:34:38
问题 In my application it is sometimes necessary to save 10,000 or more rows to the database in one operation. I've found that simply iterating and adding each item one at a time can take upwards of half an hour. However, if I disable AutoDetectChangesEnabled it takes ~ 5 seconds (which is exactly what I want) I'm trying to make an extension method called "AddRange" to DbSet which will disable AutoDetectChangesEnabled and then re-enable it upon completion. public static void AddRange<TEntity>(this