The tales of a software developer
Latest posts
-
How to log SQL queries using Entity Framework 6 like in EF Core
Watching the SQL queries Entity Framework executes is quite useful when a slow query needs optimization. If you’re already using ASP.NET Core, you might have already noticed that the debugging stream already outputs these SQL queries for you. But, if you’re working with ASP.NET MVC or ASP.NET Web API projects, by default you won’t see the SQL queries executed by EF. Even though, there’s a very simple trick to be able to see the actual SQL. Simply add the following code in your DbContext constructor. Once this piece of code has been added, you will be able to see the...
-
Why properties are evil in C#
As many of you might already know, properties are a neat way to define getters and setters. Many languages, such as C#, Delphi, Javascript or PHP support them and they are first-class citizens in the .NET ecosystem. Although properties are a handy resource, some property implementations can turn out to be evil. Very evil. Let’s dive into them. Side-effects in property code Causing side-effects is the worst practice when using properties, and it’s more spread than it seems at first. What can we consider side-effects? Modifying a nested object state, making a database query that modifies database state or change...
-
Entity Framework 6 and "There is already an open DataReader"
Entity Framework is an amazing ORM. It has differences with other ORMs like Hibernate or Doctrine, but at the same time feels more comfortable. Two key differences with other ORMs are LINQ as its query language (LINQ it’s a compiled language, if you like to rename stuff you know how many errors this feature can prevent) and being able to use foreign key values without having to join with the related entity. But, it has a poor proxy pattern. Navigation properties, the Entity Framework name for relationships between entities, can be accessed with lazy loading like in other ORMs, but...
-
ETagFilePathResult, an ActionResult to save bandwidth in ASP.NET MVC.
ASP.NET MVC provides several ways to serve files from controllers, but all of them require to serve the entire file content through the network, something that will make our website slow and more expensive while it’s ridiculous to transfer the same content over the network every time the resource is requested. Client-side HTTP caching can easily prevent downloading all those extra bytes. In this post we offer a solution to it without doing any complicated stuff, using the ActionResult abstract class to integrate a solution based on ETags in ASP.NET MVC to implement the client-side caching. Why do I need...
-
Nativescript. The native alternative to Ionic.
If we had to pick an emerging and changing field in technology throughout development today, Mobile application development would be the most accurate choice. Tools and frameworks in this field are more exposed to bigger changes. That is why, new hybrid mobile app frameworks are emerging again and one of these new frameworks is Nativescript. Nativescript is a new open-source technology by Telerik that enables developing native apps using Javascript or Typescript, that can run on Android, iOS and, in the near future, Windows, with the Windows Universal Apps flavour. This native feature is what puts the de facto hybrid...