Lately we've been wondering what people find works well for saving your business objects / entities to a database. For purpose of discussion, consider the example of an order with a few items in it (customer details, names, quantities, prices etc.). We're using SQL Server and C# and have some legacy ASP Classic/Jscript for older projects, and no chance to move to NoSQL type solutions etc.
There's roughly three ways I know of
create adhoc SQL queries on the server side (seems slower + more brittle, if you change your server side language, you have to recreate all this code)
use a stored procedure that accepts an XML representation of the order, and then the stored procedure will read the document and do whatever needs to be done. (this is the method we've used till now)
use some kind of ORM technology (I know some people swear by it, but we would prefer to avoid it as we haven't got enough experience with it to accurately gauge whether it's a path we want to go down, and there's enough chatter around performance issues and complexity that we're a bit nervous in committing to it given everything else going on, adopting a KISS philosophy)
What I want to know is:
whether anyone has any other/better approaches not in the above list that we can investigate
whether the XML method is standard/good practice. We like it because most languages support serializing to XML, it's web friendly, easy to read during debugging and pretty flexible (easy to extend, can choose how strong or weak via schemas etc.) but want to take a chance to consider other ideas.
Note: Using OPENXML in SQL Server 2008 stored proc - INSERT order differs from XML document seems to be relevant in some ways; till now we've used openxml() so I guess the question to ask would be if the XML method is a reasonable way to go, is XQuery a better approach ? Is there a handy reference/post that someone could point to on the really best way of doing things in this manner in terms of flexibility, readability etc.
Edit: Thanks for all for replying. I'll make my response even though this has been closed (still not clear why discussion is verboten on StackOverflow). Apologies for taking a while.
I should probably clarify; where we have found XML useful is when we have a "complex" object that is composed of several smaller business objects. For example an order with "items" ; there may be one or more number of items. If we load an order and then the user adds an item to their order, we just tack on another item, serialize to XML and then pass it to the stored procedure which can figure out whether it's an insert or update, whereas I'm not sure how you would do it otherwise (apart from a lot of little stored procedures/adhoc SQL which I'd avoid. ORMs: see comment below ). If we're dealing with some flat structure that amounts to an insert/update of a row, then a regular stored procedure with strongly typed parameters works well.
As for the other comments regarding ORMs; I found the links to the piece by Martin Fowler interesting. I have read the original http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx a while back but always appreciate more information. My main concern with ORM at the moment is just the complexity of learning to use it, and using it well (avoiding the pitfalls etc.) which given the current environment we're working with looks like a bit much to handle.
But thanks for the replies; just wanted to see if there were other approaches that we might have missed. Looks like ORMs are something worth investing some time in on the side.
Thanks again.
-Marcin