views:

393

answers:

7

Do any .Net O/R (object/Relational) Mappers provide Asynchronous methods out of the box?

I don't want to have to write the boiler plate for the asynchronous method if possible

I have rolled my own DAL with Asynchronous methods using the CCR framework. The CCR basically demands that I don't block any of it's threads waiting for IO responses.

The good part about my solution so far is that it is down to the bare minimum. But as this project grows in terms of scale and functionality, I am facing the mildly daunting task of maintaining raw SQL queries and boiler plate code.

BUT on the other hand if the O/R mapper Asynchronous methods are really just a messy hack that adds oddles of complexity I am not better off.

Please don't focus on alternatives to Asynchronous programming.

A: 

Nhibernate seems to be relatively easier to implement Async than LinqToSQL. See this

Personally what I would do though is use what I am comfortable with (as I haven't used NHibernate I would worry about the learning curve and potential issues so I would rather use something like LINQtoSQL or bespoke data access layer) and wrap it in it's own web service of WCF LOB Adapter.

If you really didn't want to code that yourself you could just use ADO.NET Data Services which does basically that for the Entity Framework.

Robert MacLean
+1  A: 

Yes, for SQLAlchemy (one of the best ORMs), there is sAsync:

http://foss.eepatents.com/sAsync

and NADBAPI:

http://developer.berlios.de/projects/nadbapi/

Lee B
+1  A: 

Fetching data in an asynchronous way can be accomplished in various ways. To outsource it to an o/r mapper gives challenges which you probably don't want to deal with as it doesn't really make your code less complex. The main problem is that you have to have a mechanism which is notified when the fetch is completed by the o/r mapper, so the caller is notified that data is ready.

This isn't less complex than creating a thread yourself and call the o/r mapper's fetch logic from that thread.

As you state that you want to create a webservice which should be responsive, you've to realize that the caller is outside the webservice and waits for data. I.o.w.: if the caller uses the webservice for fetching data, it's already asynchronous, as other clients will still be able to call the webservice as well: the original caller's request is handled on a different thread, logic to fetch the data is ran inside that thread, and the data is then returned to the caller.

Using asynchronous methods is of no use here, as the caller would otherwise have to be notified when the data is ready, which requires a push from the webservice to the client, which requires the client to stay connected to the webservice as long as the fetch takes anyway.

Asynchronous db interaction isn't magic things you can throw at something so it gets more responsive. Asynchronous db interaction could make the caller do other things in the mean time. However if that's already not necessary, you don't need asynchronous db interaction to begin with, which will make your code a lot less complex.

Frans Bouma
wow, ok so in summary?
Harry
In summary: you don't need async methods in your webservice as it's already using a system where a request isn't blocking other requests.
Frans Bouma
A thread blocked is one less thread available for other requests. Get enough threads blocked waiting on IO and your requests queue, the queue fills up and your now returning 'Service Unavailable' messages
Harry
Yes requests happen in parallel to each other. But they share the same system resources. So the more efficently I can use the thread pool the more requests the system can handle
Harry
Harry, you don't get my point about async methods need to call back to the caller to get their results marshalled back: how are you going to do that in a webservice? I.o.w.: what you want isn't possible.
Frans Bouma
If you're building a WCF duplex service, you _shouldn't_ block while processing requests. That is why async methods would be useful.
wizlb
One more note: You can do async pages with ASP.Net. That's another place where async db access would be extremely useful. You're wrong Frans Bouma.
wizlb
+2  A: 

I think you got it wrong. My understanding is that asynchronous execution in your case should be handled at architecture level instead of ORM level i.e. message queue driven architecture. What I see is that your webserive will only place a message in the queue and there is some kind of background agent does the asynchronous processing off the queue.

Since I don't have enough reputation to comment and Stackoverflow is alerting me inserting another "answer" I will leave my comment here.

Lee B: SQLAlchemy? How do you use it with .NET???

Jeffrey C
A: 

It sounds like you are missing some indexes.

Or you need to shift database design to OLAP model.

If that is not the case.

  1. Get more ram.
  2. Get more CPU.
  3. Partition your tables.
  4. Build a wrapper infront of the DB that can handle async requests. It will look like a queue.
Flinkman
Missing indexes? not sure how you came to that diagnosis.Would love to convince the boss to throw hardware at the problem.
Harry
A: 

While I'm not sure if any of them do it out of the box, you could use .NetTiers, which is template based. You could just add the async parts to the template. That would at least eliminate you having to maintain the boilerplate code and bare SQL queries. This blog shows how to add async calls to the MS Enterprise library (which .NetTiers can use if you choose).

As of mid-December 2008, LLBLGen Pro does not natively support async calls. Currently Genome doesn't either. It doesn't appear that Telerik does either. Pretty much just searched their documentation and looked for either async or methods that start with begin because that's the pattern.

I let the other answers speak as to if it's a good idea or not...

Bearddo
thanks. Programmers are great with advice. sometimes we just need an answer
Harry
It's not an answer, as it won't help you. But alas, I'm not the one with the question. LLBLGen Pro doesn't support async calls because it creates an awkward way of doing data-access and at the same time the developer can do it him/herself by creating a worker thread. The problem remains: callbacks
Frans Bouma
Why are callbacks a problem?
wizlb
A: 

Invist supports async methods for loading and storing data async. It is a .NET O/R Mapper.

Unknown