How to validate a XML file against a XSD file, including the referenced schemas by the XSD file in C#.

If you want to validate an XML file against a XSD file and use the XSD schemas referenced by the XSD file in the validation, you can use the following C# code:   using System; using System.IO; using System.Xml; using System.Xml.Schema; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Research.Rli { /// <summary> /// Tests …

How to name primary key and foreign key constraints, when creating a table with T-SQL.

When trouble shouting error’s thrown by T-SQL, naming your primary and foreign keys, proves to be handy. When creating tables with T-SQL, I use the naming format PK_MyTable_MyColumn1_MyColumn2 and FK_MyTable_MyColumn3_MyColumn4: if object_id(‘[dbo].[Address]’) is null begin create table [dbo].[Address] ( Id int not null identity(1,1) constraint PK_Address_Id primary key ) end …

How to change the *.mdf and *.ldf location of an online Microsoft SQL Server LocalDb database in a Microsoft Visual Studio 2010 test.

For testing purposes it is possible to copy a new localdb database to your output directory and start using this localdb database. For more information see my previous post: https://www.roelvanlisdonk.nl/?p=2607 It is possible that a previous tests run did not cleanup it’s copy of the localdb database. Now if you …

How to convert a bitmap into a 1bpp monochrome TIFF in C#

If you want to convert a bitmap into a TIFF, than then you can use the code: using (System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap(@"C:\Temp\Source.bmp")) { string outputFileName = @"C:\Temp\Destination.tiff"; if (System.IO.File.Exists(outputFileName)) { System.IO.File.Delete(outputFileName); } sourceBitmap.Save(outputFileName, System.Drawing.Imaging.ImageFormat.Tiff); } If you want to convert a bitmap to a 1bpp monochrome TIFF in C#, …

How to update an entity in the database, when state tracking is disabled in Entity Framework 4.3

When you disable state tracking in Entity Framework 4.3, for performance improvements (and you know what you’re doing ), by setting: DbContext.Configuration.AutoDetectChangesEnabled = false , then you are responsible for your own state tracking on entities.   The process of updating an entity, involves 3 steps: 1. Setting the EntityState …