‘Fluent Interfaces’ have been a bit of a buzz for probably long enough that I am not justified in buzzing about them. I was pretty excited when first seeing them applied to databases in form of NHibernate and also kind of excited to see all that code-first-ness come to Entity Framework, which had never really convinced me with the whole ‘visual design experience’ thing it had when I first looked at it way back in EF 2 or whatever. Those were the days.
It went a long time between me learning about EF, and actually getting to use it. Now I’m using it day to day. I did initially feel very excited about EF. The promise EF seems to hold me, is that it will simplify my life in pleasant ways:
1) I won’t need to learn SQL syntax. I can just use code style .Where() and .Select() – all that LINQ stuff without the language integratedness which always seemed like a demoware feature to me anyway.
2) I won’t have to manage database creation SQL scripts. I can use migrations to manage database creation and updating. The updating can even happen at app startup without me even thinking about it
3) Not only do I not have to learn SQL, I don’t even have to know much how SQL works.
Now I’ve actually been using EF for 6 months, I find myself beginning to wonder if something is wrong.
See, I’m gradually learning SQL syntax. Why? Well, sometimes I might do ad-hoc queries on data. But mostly because I want to debug and optimize my EF queries, and the only way of doing that is to see the SQL queries that these EF queries get translated into, and to run them through the SQL execution plan analyzer.
Which brings me to point number two. I’m gradually learning stuff about how SQL works. Because it turns out that SQL is really good for certain things, and not so good (fast) at others. In fact, it depends a lot on your schema, how you normalize or denormalize, and what indexes you have how fast your queries are going to be. And oh yeah – as well as indexes SQL has these notions of non-nullability and uniqueness which are kind of important. And even string length is important, because it affects what you can put in indexes.
So there we are. I’ve realized that Entity Framework is yet another leaky abstraction.