BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage Interviews Jimmy Nilsson on LINQ to SQL

Jimmy Nilsson on LINQ to SQL

Bookmarks
   

1. This is Floyd Marinescu here at the JAOO Conference with Jimmy Nilsson. Jimmy can you tell us a bit about yourself?

I am Jimmy, I am from Sweden and someone told me yesterday I had only 2 errors and one is that I like test driven development and the second is that I am from Sweden. I think having only 2 errors is good. I have been a developer for 20 years and I am into domain driven design and Agile stuff.

   

2. Can you introduce the audience to LINQ-to-SQL?

Microsoft has created a new framework for integrating queries into C# and Visual Basic. LINQ to SQL is one flavor. You could say it's for creating queries sent to the database, to a large extent, and it's also an object relational mapper, although a simple one. This is Microsoft's first attempt to releasing an object relational mapper. There were a couple of tries in the past history, but it didn't happen before, but I think it is going to happen this time.

   

3. What makes this effort better than previous efforts towards ORM and .NET?

First of all LINQ is a beautiful language in my opinion. I've tried to create a universal query language in the past and when I compared my effort with LINQ, my try was horrible. LINQ is beautiful in my opinion. So being able to use LINQ as the query language for the Object Relational Mapper is great. And there were other mappers that were quite simple to get started with, a small thing, easy to grasp, easy to get started with. And I am especially happy by this because I think this will be an eye opener for lots of .NET developers to get started with domain driven design.

   

4. Weren't all .NET developers working with table abstractions previously?

I think that is very common still. In the .NET community it's quite common to only use what Microsoft creates. Not many are going to use open source alternatives. So, all of a sudden lots of developers will see a new way of working with data and that is very exciting for me.

   

5. So technically what are some of the benefits and limitations of the current LINQ-to-SQL implementation?

Actually the main problem I think is that it doesn't support using value objects in the domain model. That is something I've grown extremely fond of in later years. I am using lots of value objects encapsulating small concepts in the domain model. Then making those concepts easy to test on their own and reusable and intention revealing. I can't use them in LINQ to SQL and that's a really big problem, I think. Except for that there are a couple of minor things of course and there are some small problems with the persistence ignorance property. I could live with that. But not having value objects support, that is hard to live with. Especially for me, coming from domain driven design.

   

6. Is there a work-around to simulate value object support in Linq?

Yes I've created an ugly one. Fortunately, I can load value objects on demand and store them in simple fields, but unfortunately then the querying will be hurt also. I spoke to Microsoft about it yesterday and they had some ideas. Perhaps they or someone else will solve it by going into the expression tree to deal with this problem, but we don't want to spend too much time with workarounds. We'd like to focus on the domain, so I don't know at the moment, what will happen.

   

7. What is the relationship between LINQ-to-SQL and the Entity Framework?

The entity framework was created by another team and they are working quite hard on that right now. I don't know too much about it, but my impression is that the entity framework is a huge thing and LINQ-to-SQL is a small graspable thing. Both are mostly coming from the database side instead of coming from the domain driven side. Perhaps, I think, the entity framework is even worse in that respect. It's not at all about persistence ignorance at the moment, as I understand it. I like LINQ to SQL since it's so small and simple.

   

8. What advice would you give developers on the design of the domain model and the mapping framework in their next .NET application?

I have to say this. And I really believe that people should read up on domain driven design. I think that is great advice for people that haven't been using rich domain models in the past. Otherwise, it's too easy to go for an anemic domain model which only has the cost without the benefits. Not putting any behavior into the domain model and only getting this mapping problem is one problem you will encounter otherwise. Another one is to create a domain model where everything is connected to everything, a kind of ball of mud. So, I think domain driven design really helps in getting started, in a nice way.

   

9. How would you compare LINQ-to-SQL to Hibernate?

Hibernate is a much more mature and a more competent solution, I would say. You can deal with more complex mapping. For example, I've been working a lot with Hibernate and it has been working great for me. If you are already using Hibernate then I don't think you would move to Linq-to-SQL. If you haven't been trying Hibernate to this date then probably Linq-to-SQL is a great start for you. There is work also going on to create Linq-to-Hibernate as one way of getting the query language on top of a great mapping engine.

   

10. What is your favorite computer book?

My favorite computer book is the book by Eric Evans: "Domain driven design". It's like poetry I think. It's not just great content, but you can read it many times and it reads like poetry.

Jan 09, 2008

BT