Re: Finally which ORM tool?
- From: James Crosswell <james@xxxxxxxxxxxxxx>
- Date: Fri, 12 Oct 2007 17:54:11 +0200
Jon Skeet [C# MVP] wrote:
In pure ADO.NET you wouldn't have had an object tree which was meant
to represent the same state as the server, so the aliasing wouldn't
have been apparent.
Wouldn't you? What kind of things would you be passing back and forth between your n-tier application server and client in an pure ADO.NET implementation of the server? Did you pass datasets back and forth? I sure didn't.
So if you don't care about session lifetimes, just create a session
for each separate query - it's very easy to do.
What I do currently is the following (Pseudocode):
void Save(object objectToSave)
{
using (Session session = InsertORMHere.NewSession())
{
object fetched = session.GetByKey(objectToSave.Oid);
if (fetched == null)
{
session.Save(objectToSave);
}
else
{
fetched.CopyFrom(objectToSave);
session.Save(fetched);
}
}
}
Which is fine and with a bit of reflection (in the implementation of the CopyFrom method, to copy object properties across) this works (and avoids an insert where an update should have occurred because of the whole business with sessions)... but it is, none the less, a workaround.
I'm not sure if you're playing the devils advocate or if you're just generally hostile to change but it seems to me that what I'm suggesting is certainly an improvement over the existing frameworks which REQUIRE me to write the above workaround because they REQUIRE sessions, even though these are not required in order for these ORMs to do their work. The idea of a session is only required by a select portion of the people using these ORMs so it seems insane to impose it on the rest of the applications using these ORMs... It's like forcing every application to choose a TCP/IP port, even if they don't use TCP/IP - what's the point??? The only thing it achieves is to inconvenience developers using these frameworks.
Surely it would be possible to overload the Save/Load methods of the
persistence framework to either take a session parameter or not. Or
maybe have two PersistenceController classes - one which is implicitly
sessionless and another which is not.
Again, it would be very easy for you to do that yourself, just
creating the session when you need to.
Yes but why should I? Why the heck isn't it built into the frameworks and why do they cling needlessly to a dependence on sessions when the OPTION to use sessions would suffice.
I've done plenty of n-tier work, and it's *not* the opposite for n-
tier frameworks. I suspect it depends on what you really want the ORM
system to do for you, but I've never regarded the session handling as
a problem, especially as Hibernate/nHibernate provide the ability to
"re-attach" an object from a previous session into a new one when you
want to.
I said sessions created a problem in n-tier (where they don't in desktop apps) and if you've done a lot of n-tier work then you must realize this is the case, since sessions in n-tier typically get created and destroyed on a per thread basis and threads get created/destroyed on a per request basis... requiring the workaround I described above in order to effect updates.
I wasn't aware of the re-attach behavior in nHibernate though... that sounds interesting and would at least reduce the amount of needless code I write to one line. I'll try to track down some info on this on the net (although one of my projects is using XPO and they don't have such a "feature"). Thanks for the tip.
Best Regards,
James Crosswell
Microforge.net LLC
http://www.microforge.net
.
- Follow-Ups:
- Re: Finally which ORM tool?
- From: Jon Skeet [C# MVP]
- Re: Finally which ORM tool?
- References:
- Finally which ORM tool?
- From: AliRezaGoogle
- Re: Finally which ORM tool?
- From: James Crosswell
- Re: Finally which ORM tool?
- From: Frans Bouma [C# MVP]
- Re: Finally which ORM tool?
- From: Jon Skeet [C# MVP]
- Re: Finally which ORM tool?
- From: James Crosswell
- Re: Finally which ORM tool?
- From: Jon Skeet [C# MVP]
- Re: Finally which ORM tool?
- From: James Crosswell
- Re: Finally which ORM tool?
- From: Jon Skeet [C# MVP]
- Re: Finally which ORM tool?
- From: James Crosswell
- Re: Finally which ORM tool?
- From: Jon Skeet [C# MVP]
- Re: Finally which ORM tool?
- From: James Crosswell
- Re: Finally which ORM tool?
- From: Jon Skeet [C# MVP]
- Finally which ORM tool?
- Prev by Date: Re: Copy Items from a Generic List into multiple Generic Lists
- Next by Date: How Can I Determine what type of IOException occurred?
- Previous by thread: Re: Finally which ORM tool?
- Next by thread: Re: Finally which ORM tool?
- Index(es):
Relevant Pages
|