If you’re using Resharper, Roslynator or similar you’ll likely see string comparisons using ToLower() or ToUpper() flagged.
Well these comparisons are not safe in all cultures. The canonical example is the ‘Turkish i problem‘ which relates to how in Turkish the dot is present on the top of the uppercase version of ‘i’ and there is no dot on the lowercase version of the ‘i’. This means using .ToLower() etc. may return different results on machines with different culture settings.
If your SQL Server database has nullable columns which contain mostly null values consider setting these columns to sparse. Sparse columns are ordinary columns that have been optimized for storing null values. Not all columns can be set to sparse and a number of restrictions apply.
Columns set to sparse require more storage space for nonnull values (4 additional bytes) than the space required for identical data in a column that is not marked sparse. This means it only makes sense to use sparse when the percentage of nulls is above a certain threshold. The threshold is different for each data type.
An except from Microsofts Estimated Space Savings by Data Type table is below. The red highlight shows how many bytes are needed for normal non sparse columns, this is regardless if they are null or not.
The blue highlight shows bytes required for non null values in sparse columns. Note null values take up 0 space in sparse columns.
The final column shows what percentage of nulls is needed for space saving of 40%. Microsoft recommends using sparse columns when savings are at least 20 – 40%. We can see in yellow that to save 40% space for int columns we need 64% of values to be null, while the corresponding percentage for datetime columns is 52%.
Determining percentage of null values in a column manually
SELECT100.0 * SUM(CASEWHENAddress4ISNULLTHEN1ELSE0END) / COUNT(*) from Address AS Address4NullPercent
where Address4 is your column and Address is your table name.
Determining percentage of null values in all columns in all tables dynamically
Note the script referenced above might take a while to run so to prevent performance issues for your existing prod processes its best to run it either after hours or on a production clone. It will produce a table similar to below.
You’ll get the biggest space savings from using sparse columns with fixed-length columns having a high null percentage in tables with large amounts of records.
Since .NET Core 3.0 your views in MVC won’t refresh after you change your .CSHTML markup. According to Microsoft this functionality was removed as a consequence of cleaning up the ASP.NET Core shared framework to not depend on Roslyn.
To have your views refresh in .NET Core 3+ you need to install the below package from NuGet
If you use both Visual Studio Code and Visual Studio and don’t want to have to remember two different keyboard shortcuts for every command you can easily configure Visual Studio shortcuts to be consistent with those in Visual Studio Code. This can be setup from the Tools -> Options -> Environment -> Keyboard settings screen.