views:

27

answers:

1

Hi,

I have this project where I would like to go from regular ADO.NET code to a more productive, more understandable, leaner and meaner OR/M system. I have the following scenario that currently works but has to work with the OR/M as well:

Orders:

  • id
  • stuff

Documents:

  • id
  • order_id
  • path

When I create a new order I attach a document. This document is given an array of binary data (a PDF file) and when I save it, it writes the binary content to the path defined. This all works and even transactionally.

Now, is it possible to replicate the same behavior using an OR/M? Clearly it is something that I will have to write manually on top of the generated OR/M code but is it doable in Linq-to-SQL or nHibernate? Which one would you recommend? And how would I hook it up to do this?

There is some other less-default behavior in my application that is a little bit difficult to replicate I think.

Cards:

  • id
  • serial
  • pin
  • puk

Modems:

  • id
  • serial
  • imei

Orders:

  • id
  • stuff

OrderLines:

  • id
  • order_id
  • stuff

OrderLineContents:

  • id
  • orderline_id
  • identifier_name
  • identifier_id

What I'm trying to do here is hook up a specific card or a specific modem to an OrderLine. By inserting 'Modem' in identifier_name and id 1 for example. This system currently works with ADO.NET but again, I wonder how easily it's replicable in an OR/M. I have read that L2S only support single-table inheritance and I think this is clearly some sort of polymorphic multi-table 'thing'.

Any help with this would be hugely appreciated :) I seek a system that could do both these scenarios or perhaps change the second scenario to something a little different if there is no other choice.

A: 

I would surely recommend NHibernate. All the stuff you mention is possible. The first scenario is pretty straight forward:

Instantiate the entities and set the data on them. Save the file to disk. Persist the entities in the database.

Wrap the whole thing i try-catch-finally to account for exceptions that requires rollback of the transaction or removal of a corruptly written file.

As for the "identifier_name" part, you could use inheritance-mapping of both single table and joined table types. But your to classes should share a common base class to do so. Another approach - that matches more your current approach, but I'm not sure I would recommend in your situation - is using the "any" mapping, that NHibernate supports.

/Asger

asgerhallas
The any mapping looks really interesting :) Thx!
SpoBo