LINQ tricks for performance (LINQ2SQL Old School)

image.png

I’m working quite a bit on the new Silicon Valley Code Camp site these days and introducing lots of new ways to view sessions.  Much of this code I’ve written over 8 years ago, long before I had so many tricks in my bag. So, one of the things we track is session interest by attendee.  To do that we have two tables, SessionAttendee and Sessions. Doing a simple join and count of the number of SessionAttendee records per session pretty much gives us what we need. Basically, we create a dictionary so we can get all the counts at once so that way, just one sql to the database interestCountsDict = (from data in meta.SessionAttendee where data.Interestlevel == 2 group data by … Continue Reading

LINQ Query Workaround for Comparing Dates (EF, LINQ2SQL,CodeFirst)

image.png

  I seem to always get this error all the time (kind of like I never learn).     Or, for you search engines reading: LINQ to Entities does not recognize the method 'System.DateTime Subtract(System.TimeSpan)' method, and this method cannot be translated into a store expression.   The solution is very straight forward.  Just pull out the Subtract and compare the dates directly like this:   DateTime compareDateTime = DateTime.UtcNow.Subtract(new TimeSpan(0, 0, 15, 0));// now get failures with last run more than 15 minutes agovar usersFailedLasttime =db.PushChannels.Where(a => a.RequestPushNotification.HasValue && a.RequestPushNotification.Value && … Continue Reading

LINQ To SQL Performance Getting Huge Improvement in EF5, Microsoft Does Listen!

image.png

  The Original Problem Back in 2009, I discovered what I considered a fatal flaw in performance using LINQ2SQL with LINQ queries.  I published 2 very popular articles on this as well as discussed it with many of my peers and Microsoft.  At the time, I was told in no uncertain terms by Microsoft that this was an inherent problem and for many reasons I did not agree with, they would not be addressing the issue.  Well, now, more than 2 years later, Microsoft has addressed this exact issue in Entity Framework Version 5 and will be providing the exact fix that is needed! http://peterkellner.net/2009/06/08/linq2sql-uncompiled-verses-compiled-iis-performance-aspnet/ … Continue Reading

Microsoft To Add Auto-Compiled LINQ Queries to Entity Framework V.Next!

image.png

  In May of 2009 I discovered some significant performance problems that I blogged about.  In summary, I had tracked it down to the issue of LINQ2SQ having to create a full expression tree on every instantiation of a LINQ2SQL query.  I’m not a compiler write kind of guy but do respect the complexity of that and doing things like building expression trees, but still this really sucked.  Using the compile syntax in LINQ2SQL is very awkward, and IMHO takes all the fun out of using LINQ2SQL.  If you don’t remember my post, here is the graph showing the evil happening.   So, what is a Microsoft MVP to do?  I complained to everyone at Microsoft I knew.  I made this my mission for about a year.  I … Continue Reading

Follow

Get every new post delivered to your Inbox

Join other followers: