{%Pragmatic Coding%} Tips and tricks for software developers.

2Jan/140

Canonical Function “EntityFunctions.TruncateTime” does not exist in MYSQL

In our project we are using CodeFirst EF and MySQL database. And I had to make some queries that excludes time from comparison. But when I tried to use "EntityFunctions.TruncateTime" function as I could use it with regular LINQ and MS SQL I've got an error {"FUNCTION [database].TruncateTime does not exist"}.

While researching network I found that EF v.4 and upper should support this function, but unfortunately it does not work for me, so I have found best solution is to create custom function for MySQL:

And now you can simply use it in your code:

Hope this article was helpful.

Tagged as: C#, mysql, sql No Comments
2Jan/140

How to combine imported and local resources in WPF user control

Hi everyone! today I will show you how to use resources in WPF.

I have several modules in my application, and there is common module that contains general staff used in multiple modules. And I need shared resources. So here is a few steps we need to gain our goal.
Read the full article...

Tagged as: C#, wpf, xaml Continue reading
20Nov/130

Get the last day of the month in C#

Hello, friends!

Today I'll give you a snippet extension for DateTime to simply get the last date of needed month.

And usage example:

Thanks for attention.
I hope this will help you a lot.

Tagged as: C#, datetime No Comments
25Jul/130

C# – Get number of days in a year

Simple snippet function to get number of days for specified year.

Tagged as: C#, datetime No Comments
12Feb/130

How to: Using TPL Dataflow for multithreaded file compression

In this small tutorial I will show you how to use TPL Dataflow  library with a quite trivial task - multithreaded file compression.

PreInit

We need to implement efficient compression of files using GZipStream  class in the System.IO.Compression namespace. It is assumed that we will compress large files that can not fit entirely in memory. Read the full article...

15Jan/132

C# ASP.NET friendly “slug” url creating

Hello friends!

I had to develop asp.net mvc controller which could accept a parameter as a slug string for friendly URL's which look like the following:

First what should be done is adding new MapRote with modified url template and parameters:

Great, we now have formatted our route for blog record url. Now we need to wtite extension method which will generate clear formatted URL. Read the full article...

25Dec/120

Visual Studio: Import and Export Breakpoints

Visual Studio saves breakpoints in a XML file. To save the breakpoints, you just need to click on the “Export” button in breakpoint window as shown in the following figure. Read the full article...

24Dec/122

How to: Using async and await in C # – Best Practices

Async and await keywords, introduced in C # 5.0, greatly simplify asynchronous programming. They also hide some difficulties, if you lose a focus. It can add some problems to your code. The following practices will serve you well if you create asynchronous code for. NET applications. Read the full article...

18Dec/120

What’s new in reflection for .NET 4.5

.NET 4.5 has some changes to the System.Reflection. The most significant is that the Type is now separated into two classes: Type and TypeInfo. TypeInfo object keeps a complete definition, and the Type now keeps only general information. If you use the reflection from your desktop or web applications for NET 4.5, then the old API is still available too, along with new reflections. Today I will focus on how to use some of the main features of the new API.  Read the full article...

17Dec/120

HTML5: Detect online status of a webpage

Html 5 being the fore runner in the Web technology today has offered a lot of benefit and enhancements that will make life of a developer easier than even before. One of such enhancement belongs to the support of offline data storage inside browser cache.  The offline data storage enhances the UI Experience of the end user by providing rich api to read local storage.

HTML 5 supports the features that was never present before and we needed to rely on those events only using 3rd party plugins. Say for instance, you have a requirement to continue using your web application even though there is no availability of Internet.  In this tips, I will show you how easily you can detect whether the site is running in online or offline mode. Read the full article...