Connecting With Old Databases

Saturday, November 11, 2017


Washing Clothes The Old Fashioned Way

Do you know how to wash clothes using a washboard? If you've answered yes, you're probably dead and looking over someone's shoulder reading this blog. It was the first mechanized way to wash clothes and probably way faster than washing clothes with soap and a scrub. Now we have the washing machine and you probably don't even think twice about how easy it is to throw clothes into a machine and do the washing for you while you go off and do other important things. Of course, you can't wash all type of clothes this way, especially the ones that have a "Dry Clean Only" warning. You probably shouldn't even let that type of clothing touch the washer or it might spontaneously tatter. The fact is, you can't throw it in the washer. This was my current dilemma. I have a "Dry Clean Only" zoot suit (old database server) that I want to wash (query) with my snazzy washing machine (EF Core 2.0), which I simply can't do. It's not the best analogy, but I don't want to spend more time thinking of another analogy.

TL;DR

I use Dapper in my new projects to talk to old database servers that EF Core 2.0 can't talk to, specifically SQL Server 2005 and older.

Technically Speaking

I'm currently working on upgrading aging infrastructure, which of course means legacy everything. I'm sort of spoiled, because I've been happily using Entity Framework to create and query my data for greenfield projects. I've gotten so used to it, that I forgot that I even used it to connect to older databases that lived on SQL Server 2005, yes 12 year old technology. I was fine doing that until I decided I was going to make the plunge and start using ASP.NET Core 2.0, which uses EF Core 2.0. Everything was going good until I realized you can only use EF Core 2.0 with SQL Server 2008 and up, which I totally understand. I didn't want to do the object mapping myself, because I think it's a waste of time if you can use something that does that for you. I'm all about using tools if it makes code more readable, of course, there are always exceptions.

Who Is This Dapper Fellow?

I had lately come across blog posts mentioning Dapper and so I looked into it and it really didn't tickle my fancy, because you still have to write the actual sql query, bleh! Then I thought about it some more and realized that this is still better than no ORM, because at least I get the object mapping, which is really what I'm after. The best part is that it can talk to 12 year old databases like SQL Server 2005. The bonus of using Dapper, based on performance benchmarks (from rando blogs like mine), is that it's pretty fast compared to other ORMs. EF Core 2.0 apparently still gives it a run for its money, which is pretty cool, because you'll find no shortages of complaints about EF performance. Performance hasn't been a major issue for me with, but that's probably, because I'm not developing apps that get queried constantly by trillions of users. Using Dapper adds yet another dependency, but this is a temporary solution until the old database moves to a newer one, which is another project in itself. Once, the old database is updated, then I'll just go back to using EF Core 2.0 goodness.


More Posts