Simon Hughes

Thursday, 15 January 2015

Using the methods below, you can obtain the stored procedure return value, along with your data, which I've not seen in other blogs.
A stored proc should return 0 for success, and any other value for a failure.

Wednesday, 10 December 2014

When Entity Framework
starts, it first builds a set of internal views that describes the database in an agnostic way. All further processing (queries, updates etc.) EF
does, is performed against these views. Generating views however can be
costly and will impact start up time of the
application.
The startup time for a 1000 table context can be in excess of minutes.

However, this can be worked around by generating views at design time by using EFInteractiveViews Nuget Package. It allows you to pre-generate and save the generated views to a file. Neat!

Thursday, 10 July 2014

I discovered a problem when inserting data in our database. My insert statement was checking for the existence of data in the WHERE clause to prevent duplicate data being inserted. None was detected, and the INSERT happend. However, the unique constraint rejected the data as it already existed in the database.

The problem was the data to be inserted was DATETIMEOFFSET(2) and the database field being inserted into was DATETIME.

Tuesday, 12 November 2013

Summary

There are a few blog posts about using NServiceBus and encrypting strings using the WireEncryptedString type. However, you can also mark an ordinary string to be encrypted via configuration, which is more desirable as you can remove the dependancy from NServiceBus from your common Messages library.
There is a gotcha though, if you ever mix the two, then WireEncryptedString go back to being unencrypted in MSMQ. This blog post explains how to easily fix this, and also how to remove NServiceBus from your Messages library. Win Win.

<MyMessage> <Secret1> <Value>You should not be able to read this in MSMQ</Value> </Secret1> <PlainString>k9FJRIfCMmyOW4ev8wytLIg56wEKsSbg1stmSo8Wu44=@XEx7Gkaks5nfhrQAuS2kZw==</PlainString></MyMessage>

Whoops!

The PlainString is now encrypted as we want, but in doing so the Secret1 string has become plain text. The Secret1 string is still a WireEncryptedString type and yet it still insists on being plain text, just because we've used the DefiningEncryptedPropertiesAs property on NServiceBus.

Let's fix it

We do this by changing ConventionsConfiguration class to also include the WireEncryptedString type as follows:

Voila!

Both strings are now encrypted. You can see they are slightly different in the message.
To access Secret1, you do it via the .Value() method on Secret1. To access the plain unencrypted text on PlainString, you simply access the string as normal. Both strings are encrypted and unencrypted for you by NServiceBus.

How to remove NServiceBus from our Messages library

Now we have a way to tag strings to be encrypted, we can alter our message class to be:

Changing
mappings during runtime is not possible/expensive. A specific
DbModelBuilder can be used for each needed database schema. Thanks to meixger.

Added ability to detect and use .IsRowVersion().

Added
many-to-many mappings. The generated code now includes calls to .Map().
Therefore the generated code will be different to what you had
previously in v1 if you have many-to-many table mappings in your
database. Hence the revision change to v2.0.0 as I'm using semantic versioning.

Whats new in v1.12:

VARBINARY(MAX) is now correctly assigned to byte[]. Thanks to Luke91577.

Including views is now working. For a view to be included, at least one column must not be nullable. Thanks to Delmo Carruzzo.

Added
selective generation of components (Poco, Context, UnitOfWork,
PocoConfiguration). You can now build entities in your Model project,
and context, configuration, unit of work in your Data project. Thanks to kscelfo.

Added PrependSchemaName flag. You can now control if the schema name is prepended to the table name. Thanks to kscelfo.

Whats new in v1.10:

Added
UseCamelCase flag to the tt file. You can now control if you want your
table and column names CamelCase or left alone: i.e. FieldPersonOrder or
field_person_order

Whats new in v1.9.2:

Removed
the Linq de-duplication code as it is now being done in SQL. The Linq
version did not include the schema name when de-duplicating FK's.

Whats new in v1.9.1:

Added DISTICT to the foreign key SQL. This prevents duplicates from appearing. They can appear with SQL such as:

Monday, 10 December 2012

I saw a spike on the Entity Framework open-source project I created, and had a look around to see what it could be…
Found it listed as the top link on http://www.alvinashcraft.com
As developers we take so much (understatement) from the open-source community ourselves, it’s nice to give back from time to time.

I've also noticed that it is now listed in the "most popular" category in the VisualStudio add new item.

WITH
L0 AS (SELECT 0 AS C UNION ALL SELECT 0),
L1 AS (SELECT 0 AS C FROM L0 AS A CROSS JOIN L0 AS B),
L2 AS (SELECT 0 AS C FROM L1 AS A CROSS JOIN L1 AS B),
L3 AS (SELECT 0 AS C FROM L2 AS A CROSS JOIN L2 AS B),
Nums AS (SELECT TOP(49) ROW_NUMBER()
OVER(ORDER BY (SELECT 0)) AS n FROM L3 ORDER BY n),
Choice AS (SELECT TOP(6) n FROM Nums ORDER BY CHECKSUM(NEWID()))
SELECT STUFF( (SELECT ',' + CAST(n AS VARCHAR(10)) AS [text()]
FROM Choice ORDER BY n
FOR XML PATH('')), 1, 1, '')

Friday, 23 March 2012

There is sometimes a problem of wanting to remove data (email addresses in this example) from within a string which are delimited.

For example, if you want to remove all non bybox email addresses from "some.name@bybox.com; simon@hicrest.net; fred.bloggs@bybox.com"
and do this for every table, without having to create functions to break apart the string first, how are you going to do it?

Tuesday, 20 March 2012

With C# 5, you can put a special attribute on an optional parameter and the compiler will fill in the value not with a constant but with information about the calling method. This means we can implement the Logger.Trace to automagically pick up where it’s being called from:

Thursday, 1 March 2012

Some said it was the Y2K bug we had to worry about, but it's actually Tue Jan 19 2038 03:14:07 you've really to worry about.

There are many, many systems built with time saved as a 32bit long integer value.
The max value of a signed long integer is 2147483647. This value is the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC)

Wednesday, 29 February 2012

PowerShell Script files

Change and replace the following url

Change https://your fogbugz root url to be your root url for fogbugz. For example, if your companies fogbugz url is something like https://secure.bbc.com/FogBugz/default.asp, then your root url will be https://secure.bbc.com

Obtaining a Kiln Token

The first thing you need to do before you can use this script is to obtain a Kiln token. Copy and alter the following link in your browsers URL https://your fogbugz root url/FogBugz/api.asp?cmd=logon&email=[yourEmail]&password=[yourpassword]
Changing the text in square brackets (and also removing the brackets).
You should receive something like this:

ymjt123f8882a6s7td0j8eefa6u2g8

Take the token text: ymjt123f8882a6s7td0j8eefa6u2g8 and paste it into the powerShell script (edit your local copy instead of the SVN one)

Running the script

Start PowerShell and run the script passing in the root path of your Kiln repos.

Will it clone everything?

It could, including branches, but by default I've set it not to clone QA/PROD/UAT repos, or branches.

How to clone branches

How to clone QA/PROD/UAT repos

Modify the function CanCloneRepo() which is used to filter out repos you may not want.
If you want all repos, simply return 1; from this function.

This script will also remove repository folders from your drive where the repo no longer exists in Kiln!

This prevents orphaned code on your drive. However, if you don't want this functionality, simply remove the following code situated at right the bottom of the script:
By leaving the above code in, your repository folder structures will be standardised to how its organised in Kiln. I've tested it and it works. Have faith ;-)

About Me

Currently lead developer at www.bybox.com
C++, C# and SQL developer for 26 years and love what I do. UK Senior software developer / team leader / tutor.
Author of http://ReversePoco.com
UK Senior software developer / team leader.
I've been writing software since 1985. I pride myself on designing and creating software that is first class. That means it has to be fast, scalable, and with good use of design patterns.
I have done everything from risk analysis and explosion modelling, banking systems, to highly scalable multi-threaded arrival and departure screens in many leading airports, to state of the art wireless warehouse systems.
Email: simon@hicrest.net