My random thoughts on software development

Month: May 2016

Year first date literals in Visual Basic .NET

Since I write on a daily base unit tests, I’m wondering more and more why there is not an easy – and especially unambiguous – way to provide a hardcoded date to a variable or procedure argument. Do you know, without any doubt, what this date actually means?

Dim thisYearsBirthday As Date = #5/6/2015#

Was I born on the 5th of June or the 6th of May? Visual Basic .NET will support now a good ISO-standard, which starts with the year. It follows the convention of ‘yyyy-MM-dd’ and you can even use slashes as separators. You can also provide the time if you want.

Dim todayDateWithDash = #2015-02-13#
Dim todayDateWithSlash = #2015/2/13#
Dim nowDateTime24 = #2015-02-13 19:59:00#
Dim nowDateTime12 = #2015-02-13 7:59:00 PM#

Console.WriteLine(nowDateTime24.ToString("yyyy-MM-dd HH:mm:ss"))
Console.WriteLine(nowDateTime12.ToString("yyyy-MM-dd hh:mm:ss"))

The results are shown in the screenshot below. Please note that you can specify the time part as 24-hour format as well as the 12-hour format. The ToLongDateString() extension methods formats the dates to the Dutch language, but I’m sure that you will understand the concept.


BTW… for the people who are still doubting about my birthdate… I was born on a 6th of May!

Show generated SQL of Entity Framework in Visual Basic .NET

When you are writing LINQ queries against an Entity Framework context, you don’t have to worry about the SQL which is generated and executed. However, in some cases you may be interested in this SQL. It’s quite easy to switch on a logging mechanism which will be display all executed SQL in your Debug window. You have to provide an Action to the DbContext.Database.Log property. You provide a lambda with the functionality you want. If you want you can log this output also to a file or for example the Clipboard.

Continue reading

© 2017 Obelink.ToString()

Theme by Anders NorenUp ↑