Browsed by
Tag: .Net

IEnumerable vs. IQueryable

IEnumerable vs. IQueryable

It is extremely important that the programmer knows the difference between IEnumerable and IQueryable. When used in the Service layer, which communicates with the Data layer, the performance difference is extreme. IEnumerable causes a query to bring over all of the query’s table rows and then filter them (your WHERE clause) on the web server by iterating over every row and applying the “WHERE”. That’s work not intended for a web server and can mean the difference between a quick…

Read More Read More

A Stored Procedure Helper in .Net C#

A Stored Procedure Helper in .Net C#

I wrote this helper to make calling SQL stored procedures easier and less error prone. The idea here is to encapsulate the parameters of the stored procedure in an interface method that gets implemented for each stored procedure. The values of the input parameters are encapsulated in an object. It makes use of Microsoft’s (now defunct) Enterprise Library DAAB (https://learn.microsoft.com/en-us/archive/msdn-magazine/2005/august/the-enterprise-library-data-access-application-block-part-2). Here’s the interface definition: Here’s the definition of a class named “LoginParameters” that implements the interface “IPrepareSpParameterValues”. It encapsulates the…

Read More Read More

JSON Date Serialization C# Snippet

JSON Date Serialization C# Snippet

When exposing .Net DateTime members to service consumers the .Net format is not always appropriate because the consumer may not be on the .Net platform. Therefore it’s best to use the ISO 8601 standard. Serialization is performed in .Net by using the OnSerializing attribute, and deserialization by using the OnDeserialized attribute. I created a Visual Studio snippet that writes the code that enables you to serialize/deserialize your DateTime member. Once added to your Snippets library utilize it by typing “jsd”…

Read More Read More