Month: September 2014

Using InverseProperty and ForeignKey Attributes

InverseProperty and ForeignKey are (arguably) the most commonly used attribues in Entity Framework when developing in code-first approach. They help greatly simply the job of managing our models. Foreign Key In order to introduce foreign key to our code we need to specify to what objects it maps to. So there are two things that

Continue Reading

Removing Entry from a Database using Entity Framework

Most of the tutorials on the internet seem to focus on how to remove these objects from DataContext as opposed to DbContent. However, if your database is built using code first approach you are unlikely to be using DataContext/. In order to delete an entry from the database, firstly Remove the element and then save

Continue Reading

Proper way of returning multiple values from a method

Since C# 7 you can make method signatures which correspond to multiple values In Python, you can return multiple values from a function. This functionality is not however built-in into C#, shame. I think this is a nice feature of the language. It frequently reduces asymptotic complexity (i.e. "performance") without resorting to implementing another class

Continue Reading

Using #region to improve readability of your Code in VS

#region is an interesting instruction that tells Visual Studio how to wrap the code into 'meaningful' chunks. In larger classes, especially, those with several interfaces it is particularly helpful.

Pretty handy if you ask me. The downside is, and I have seen this already a couple of times, is that some engineers use them

Continue Reading

Returning Http Error as Response in WCF

This is arguably one of the more irritating things in WCF, but as it turns out for good reason. WCF is meant to expose services 'universally' of their endpoint i.e. it shouldn't matter how you connect to the server, the service is independent of the underlying protocol. Therefore, returning HTTP errors from WCF service, well,

Continue Reading