[ASP.NET Core 1.0] Automatic Migrations in Entity Framework 7 (EF Core 1.0)

1
Comments
[ASP.NET Core 1.0] Automatic Migrations in Entity Framework 7 (EF Core 1.0)

There is no more public Configuration() { AutomaticMigrationsEnabled = false; } in Entity Framework Core 1.0 (formerly  EF 7.0) Now you can use extension Migrate method during database initialization. For example, you have custom DBInitializer class: public class DBInitialization { public static void Initialize() { using (var context = new DbContext()) { context.Database.Migrate(); // Other db initialization code. } } } There is also async version of this method. This method will apply any pendi...

Read further...

ZohoPeopleTimeLogger v1.3 - Show me the error

0
Comments
ZohoPeopleTimeLogger v1.3 - Show me the error

At Novility, we have  found that we cannot log working time anymore. You just press "Make me happy" button and nothing :( When ZohoPeopleTimeLogger tries to make you happy it needs information about current jobs from ZOHO. For example, if I try to log time for January 16 and there is no job for this date I will get an error. But user was not able to see that error. That is fixed in release v1.3. Download GitHub User will see message box with detailed description and nice instructions:

Read further...

Build and test ASP.NET 5 application using AppVeyor

1
Comments
Build and test ASP.NET 5 application using AppVeyor

For those who do not know, AppVeyor is Continuous Integration and Deployment service for .NET projects. It is free for open-source projects. Currently, AppVeyor supports latest DNX version (1.0.0-rc1-final) and I've recently migrated my pet project to this version. I will show you how easy it is to build and run all unit tests on CI server every time you commit to GitHub. Visual Studio project (MSBuild) In LearnWordsFast project we are using Visual Studio 2015 as a development environment, so in...

Read further...

[WPF][MVVM] TreeView: Scroll To Selected Item

0
Comments

Here is the MVVM way to bring selected TreeViewItem into a view. First we need an attached behavior. We cannot use regular behavior because we will attach this property through Style. public class BringSelectedItemIntoViewBehavior { public static readonly DependencyProperty IsBringSelectedIntoViewProperty = DependencyProperty.RegisterAttached( "IsBringSelectedIntoView", typeof (bool), typeof (BringSelectedItemIntoViewBehavior), new PropertyMetadata(default(bool), PropertyChangedCallbac...

Read further...

[ASP.NET 5] Production Ready Web Server on Linux. Kestrel + Supervisord

2
Comments
[ASP.NET 5] Production Ready Web Server on Linux. Kestrel + Supervisord

In the previous article I've used nohup + su + init.d script to run kestrel in a background. But as Daniel Lo Nigro suggested in comments it's much easier to do the same with Supervisor And he was absolutelly right, config is much smaller, and you can easelly see status and output of a program. First, install supervisor: sudo apt-get install supervisor Now you can create config for your application: sudo nano /etc/supervisor/conf.d/kestrel_default.conf With following content: [program:kestrel_de...

Read further...

C# 6.0 await in catch/finally

2
Comments
C# 6.0 await in catch/finally

C# 6.0 become more asynchronous-friendly than before. Finally, you can use await keyword in catch and finally blocks! Here is example: class Program { static void Main(string[] args) { do { Console.WriteLine("Before caller " + Thread.CurrentThread.ManagedThreadId); CallerMethod(); Console.WriteLine("After caller " + Thread.CurrentThread.ManagedThreadId); } while (Console.ReadKey().Key != ConsoleKey.Q); } public static async void CallerMethod() { try { throw new Exception(); }...

Read further...

C# 6.0 Detailed Overview Of The New Features

0
Comments
C# 6.0 Detailed Overview Of The New Features

C# 6.0 has a lot of great new features, which save developer's time and make code more clean and short. At the conclusion of the C# 6.0 series let's go through the whole list of the new C# 6.0 features again (all titles are active). Each article contains detailed explanation of the particular feature with resulted IL code and "old-school" way of doing the same things. String Interpolation var a = 1.2345; Console.WriteLine($"test {a}"); Console.WriteLine($"test {a} {a} {a}");...

Read further...

C# 6.0 Expression-Bodied Methods

2
Comments
C# 6.0 Expression-Bodied Methods

The last but not the least feature of the C# 6.0 that I am going to cover is expression-bodied methods. We all have experience writing single line methods: private string name; public override string ToString() { return "Name :" + name; } Now, we have shorter way of defining the same method: public override string ToString() => "Name: " + name; As you can see, now we can use lambda style to define method's body. But there is one difference from lambda expressions, we canno...

Read further...

C# 6.0 Index Initializers

0
Comments
C# 6.0 Index Initializers

Hi, folks! Today we are gonna talk about new indexer initialization syntax introduced in C# 6.0. As we know, we already have good way to initialize dictionary: var dic = new Dictionary<string, int> { {"Apple", 2}, {"Pear", 10} }; but in C# 6.0 we have a better way to do the same: var dic2 = new Dictionary<string, int> { ["Apple"] = 2, ["Pear"] = 10 }; As for me, it is a bit nicer because we already have curly brackets in the beginning and endin...

Read further...

C# 6.0 Exception Filters. try catch when

0
Comments
C# 6.0 Exception Filters. try catch when

Exception filters is a new C# 6.0 feature. Visual Basic.NET and F# have this functionality for a long time. That is because exception filtering was implemented in CIL but not in C#. Now, this technique available for us. That's how you can use it: try { Method(); } catch (Win32Exception ex) when (ex.NativeErrorCode == 0x07) { // do exception handling logic } catch (Win32Exception ex) when (ex.NativeErrorCode == 0x148) { // do exception handling logic } catch (Exception) { // log unhandled excepti...

Read further...

C# 6.0 Auto-Property Initializers

0
Comments
C# 6.0 Auto-Property Initializers

The next new feature of the C# 6.0 is auto-property initializers and get-only auto property. The main problem that they suppose to solve is immutable type declaration. Before C# 6.0, if you want to create immutable type with properties, you have no possibility to use auto property: public string Property { get; set; } So, you were forced to use regular get-only (read-only) property with read-only backing field: private readonly string prop; public string Prop { get { return prop; } } public Ctor...

Read further...

C# 6.0 nameof Operator

1
Comments
C# 6.0 nameof Operator

C# 6.0 has a lot of new features, one of them is nameof operator. Let's see how it's implemented internally and what we can do with it. This operator will help us get rid of "magic strings" in our code. We all know following use case: public void Method(int arg) { if (arg < 0) { throw new ArgumentOutOfRangeException("arg"); } } With nameof operator we can rewrite code in a nicer way: public void Method(int arg) { if (arg < 0) { throw new ArgumentOutOfRangeException(nameof(arg));...

Read further...

C# 6.0 Null Propagation Operators ?. and ?[]

1
Comments
C# 6.0 Null Propagation Operators ?. and ?[]

C# 6.0 introduced two new null-propagation operators: ?. and ?[]. They will make null reference check much easier. In this article, we will see how they work and how they implemented internally. We all know about NullReferenceException and how to avoid it in our code. We just need to check everything for null before accessing some fields\properties\methods. Null Propagation Operator ?. var str = GetString(); if (str != null) { return str.Length; } else { return 0; } Now we can use Null Propagati...

Read further...

C# 6.0 String Interpolation

0
Comments
C# 6.0 String Interpolation

One of the top ten requests on uservoice is String Interpolation. Today we are going to see how to use this feature and how it is implemented in C# 6.0. We all use similar expressions: var str = string.Format("Date: {0}", DateTime.Now); This is string interpolation in C# before 6.0. Now, in C# 6.0, we have new string interpolation technique: var str = $"Date: {DateTime.Now}"; There was nothing new added in to runtime, this is just a syntaxis sugar for "old shcool" interpolati...

Read further...