From NHibernate to Entity Framework 6 - Part 1: the mapping story

This is the first part of an n-part series on using Entity Framework 6 coming from an NHibernate background . Although this series is primarily aimed at NHibernate veterans making the transition to Entity Framework 6, any developer new to EF will probably find most of this information helpful too. Introduction After having used NHibernate quite extensively for the past few years, I've just completed my first 6 months in the Entity Framework world. I had actually already given Entity Framework a try back in the EF4 days. I quickly abandonned it as it became clear very quickly that it wasn't ready for prime time. But I have to say that Entity Framework has come a long way since then. EF6 has become not just a usable but a very capable ORM. It's definitely now a very credible alternative to NHibernate. The transition from NH to EF6 was fairly smooth as … [+]
Read more

Generating HTML emails with RazorEngine - Part 04 - Taking a step back: behind the scenes of Razor and RazorEngine

This is the fourth part of a 10-part blog series. You'll find a list of all the posts in this series in the introductory post. Make sure to review the Before we start section in the introductory post. All the source code is on GitHub. Comment? Bug? Open an issue on GitHub. Before diving any deeper into RazorEngine, it's worth spending a few minutes getting a good grasp of what Razor and RazorEngine really are and of how they work under the hood. It will save a lot of time and frustration when trying to customize or understand RazorEngine's behaviour. This is a very quick and deliberately simplified overview of Razor. What is Razor? Razor is a language that lets you create document templates mixing static markup and code. Typically, the static markup is HTML and the code is C# or VB.NET. But it doesn't have to be. Razor … [+]
Read more

A tale of debugging - the LinkedIn API, .NET and HTTP protocol violations

In my last project, I was in charge of integrating the LinkedIn API into .NET 4 application. A few weeks after launch and during a client demo (of course), a request to the LinkedIn API failed with the following cryptic WebException: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF We had thouroughly tested the LinkedIn API over several months before launch, had a dedicated team of testers and had a full suite of automated integration tests against the API, yet had never seens this error before. In fact, I'd never seen this error before in my life - and I've implemented my fair share of third-party REST API integrations. Since we were investigating another issue at the time, we put that one down on a temporary network glitch and moved on... ...until both our QA team and our automated tests were able to … [+]
Read more

Generating HTML emails with RazorEngine - Part 03 - Caching, VS integration & namespace config

This is the third part of a 10-part blog series. You'll find a list of all the posts in this series in the introductory post. Make sure to review the Before we start section in the introductory post. All the source code is on GitHub. Comment? Bug? Open an issue on GitHub. Caching templates with RazorEngine When generating our email in the previous post, we happily ignored the cacheName parameter of the TemplateService.Parse() method. This was wrong. Not using RazorEngine's cache will result in both dreadful performances and memory leaks. Generating a document from a Razor template involves some very expensive operations. We'll cover this in more details in the next post but in a nutshell, TemplateService.Parse() will: Parse your template and generate the source code of a class that can generate the final document. Compile that class on the fly into its own assembly. Load that newly … [+]
Read more

Generating HTML emails with RazorEngine - Part 02 - Basics: generating your first email

This is the second part of a 10-part blog series. You'll find a list of all the posts in this series in the introductory post. Make sure to review the Before we start section in the introductory post. All the source code is on GitHub. Comment? Bug? Open an issue on GitHub. As indicated in the introductory post, we'll work from a console application. The email template For this example, we'll generate a simple Welcome email. We'll start with a basic model for our email: namespace ConsoleApplication.Models { public class UserModel { public string Name { get; set; } public string Email { get; set; } public bool IsPremiumUser { get; set; } } } We can then implement our email template in the same way as we would implement an ASP.NET MVC Razor view. Here, we'll use a strongly-typed model: @model ConsoleApplication.Models.UserModel <!DOCTYPE html> <html lang="en" xmlns="http: … [+]
Read more