Subscribe to this list via RSS Blog posts tagged in linq to sql

Posted by on in Blogs
In LINQ, Don't Use Count() When You Mean Any() If you have a list, array, or query in a C#/LINQ application and need to check and see if the list is empty, the correct way to do this is to use the Any() extension method: if (q.Any()) { Similarly, you can check to see if any elements in the list meet a certain condition: if (q.Any(i => i.IsSpecial)) { If the query provider is something like LINQ to Entities, this will be translated into fairly efficient SQL using EXISTS. For some reason, I see a lot of people write this co...
Don't Depend Upon the ASP.NET Membership Tables One very popular option for implementing user security in ASP.NET is to use Forms Authentication with the SQL Server membership provider. This provider creates several database tables to store user-related information, as well as a number stored procedures. From time to time, a developer will attempt to add the ASP.NET Membership/Forms Authentication tables to their Entity Framework model (or LINQ to SQL, NHibernate, etc.) model. Before doing this, they will often have created referential con...
join in LINQ to SQL and LINQ to Entities Considered Messy, Redundant In this post I will demonstrate that use of the join keyword in LINQ to SQL and LINQ to Entities is nearly always wrong. LINQ queries which you write with the join keyword are harder to read and write than queries you write using associations, and they require knowledge of database metadata which is not required otherwise. This introduces the potential for errors and makes maintenance harder. Many people ask how to do a "left join" in LINQ to SQL, and unfortunately, the answer they nearly alw...

Posted by on in Blogs
Skip(0) in LINQ and Testing A couple of weeks ago, I wrote In LINQ, Beware of Skip(0). In that post, I observed that calling Skip(0) on a query result in LINQ, which has no effect on the dataset returned, imposes a performance penalty with at least some LINQ providers. At the time I commented that there might be some desirable behavior of this that I had missed. Sure enough, one of the developers on the LINQ to SQL team noted in comments that Skip(0) will cease to be a no-op in LINQ to SQL in .NET 4.0, and supplied a perfe...
Using jqGrid with ASP.NET MVC: Understanding LINQ Errors If you spend enough time with the PagedList class that I've been using for paging in the method which supplies data to jqGrid, it's a near-certainty that sooner or later you will see a LINQ error with Count in the call stack. The error may seem confusing, because it has nothing to do with Count. Commentor Graeme has been experimenting with my demo solution, and has run into just this issue: Finding your blogs very helpful - superbly written - just found out about jqgrid last night and have inte...
  • Page :
  • 1

Check out more tips and tricks in this development video: