Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Persistence Ignorance with LINQ To SQL

I do not usually just re-point to older blogs, but some people including Don Smith were asking in the Persistence Ignorance session at Alt.NET Seattle about support for PI with LINQ To SQL.

I would maintain that LINQ To SQL supports a PI approach. I talked about it originally here but you might also want to read the relevant sections of my series on Architecting Applications with LINQ to SQL which cover mapping here and here.

The major lack is around support for a fine-grained object model i.e. you can’t map a value type to one or more columns only entities to tables. However, I don’t think that is a PI issue, but a modelling issue.

About Ian Cooper

Ian Cooper has over 18 years of experience delivering Microsoft platform solutions in government, healthcare, and finance. During that time he has worked for the DTi, Reuters, Sungard, Misys and Beazley delivering everything from bespoke enterpise solutions to 'shrink-wrapped' products to thousands of customers. Ian is a passionate exponent of the benefits of OO and Agile. He is test-infected and contagious. When he is not writing C# code he is also the and founder of the London .NET user group. http://www.dnug.org.uk
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://khvdjtae.com/ Ukbalneb

    iuipHr

  • Christian

    NP, I also appreciate this fact, and agree with your point. At the moment I am just wishing for things to go even further PI wise for the ORM (or ORM like) frameworks across the board.

  • Ian Cooper

    @Darnell

    I think like a lot of things PI is a goal. The closer you can get to a domain model that is not impacted by your persistence choices the better your life will be.

    NHibernate seems to be the closest thing out there today to getting to true PI.

    @Kazi @Christian
    Sorry if I came over a little hard. I was hoping to just raise the point that L2S went a long way towards trying to achieve PI, and we should give positive feedback about that.

  • darnell

    A better name would be PF (Persistence Flexible). I don’t think PI exists in real world.

  • http://weblogs.asp.net/rashid kazimanzurrashid

    @Ian: I am active reader of your blog and I have gone through many time of those posts. I have not tried NH though I have plan to do some investigation, this is so far my experience with L2S while creating a loosely coupled application where i can replace the data access layer without modifying other parts.

    ORM without Lazy Load smells very dump, though it a another tale whether Lazy Load is blessing or curse.

  • Christian Nielsen

    I am not comparing to NH with my reply, because I am aware that there is no solution that gives me all that I would like in the sense of PI. Actually I think L2S and L2E for that matter have come a very long way and that they are great.

    Actually a thing I hope to see solved is to combine the use of a ORM (or ORM like) tool with DI. It would be beautiful to be able to make mappings against an interface and just declare in one place which implementation to use. This is what i would normally wish to do, but its almost impossible with HN/L2S etc. as it is today imo.

    I have no idea if anyone has this in their roadmap, but if you guys out there agree maybe it would be worth pushing for?

  • Ian Cooper
  • Ian Cooper

    @Kazi, @Christian

    In addition, you can use L2S without using either EntitySet or EntityRef in case you did not know. You just won’t get lazy loading. EntitySet and EntityRef are only required to support lazy loaded collections.

  • Ian Cooper

    @Kazi, @Christian

    If you follow the links to the original articles I make reference to the fact that we have to use EntityRef and EntitySet instead of an underlying abstraction. There is some friction there.

    To be fair though NHibernate has some friction there too. I need to use a polymorphic type for my collection, and IList does not have the semantics many people expect (acting either as a bag with repeats or needing an ordering). For many developers the use of ISet, the common choice, to represent their collections is not friction free.

    When choosing a tool you need to compare your values against the features of the tool. So if your value is Persistence Ignorance then you need to figure out which tools have less friction than others to support your goal.

    PI is an ideal, but you may have to make some trade offs. For many people using EntitySet is friction free enough, for others not.

  • Christian Nielsen

    I agree with Kazi – it’s the very definition, because there is not much ignorence if you need to know these things…

  • http://weblogs.asp.net/rashid Kazi Manzur Rashid

    Don’t Agree.
    Apart from Jimmy Nilsson 7 rules of PI, I do have a simple and basic rule.

    “If you cant code without referring the underlying Data Access Technology in your client, it is not PI”.

    and for L2S the EntityRef and EntitySet is the culprit.