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

A Cool / Unexpected Refactoring around .Net C# Locking Issue

I’m constantly amazed by the insightfulness of ReSharper’s suggested refactorings (ReSharper is a Visual Studio Addin from JetBrains I use with C#). Today, I’ve been working on a threading problem where I’m getting crashes based on what seems like not proper locking across threads (they usually show up as some type of ugly update object or enum error). My code starts like this:   public static List<DbProgressReport> DbProgressReportProperty { get; set; }   … Continue Reading

Follow

Get every new post delivered to your Inbox

Join other followers: