views:

36

answers:

1

I have a Repository that should adapt itself to any kind of data source.
This includes certain types of web services, databases (using ActiveRecord and NHibernate) and even flat files.
For ActiveRecord I have EnumerateQuery(IActiveRecordQuery query) which returns an IEnumerable just like I need but the interface is undocumented.
What exactly does it do? How do I use it?
Can I use it to extend my Fetch() function to accept other data sources?
Can I wrap it with my own class in order to accept other data sources?

+1  A: 

I'd use IQueryable as an abstraction instead. Make your IRepository implement IQueryable, then the ActiveRecord repository would delegate to Castle.ActiveRecord.Linq, flat file repository would be implemented using LINQ to XML, etc.

Mauricio Scheffer
But what about DetachedCriteria?
the_drow
@the_drow: if you expose DetachedCriteria in your abstraction then you're already bound to NHibernate and it's really a leaking abstraction. If you really need to make your repository datasource-independent, IQueryable is the way to go, that's what it was built for.
Mauricio Scheffer
Yes, the problem is that my queries are already written with DetachedCriteria. Do I need to use generics for this purpose?
the_drow
Also, how would you implement IQueryable for a repository? Got any example? Should I just use IActiveRecordQueryBase and IQueryable as both overloads for Fetch()?
the_drow
@the_drow: lots of IQueryable-based repositories on the web, for example http://www.jeremyskinner.co.uk/2008/03/24/linq-repositories/ http://www.codeinsanity.com/2008/08/implementing-repository-and.html
Mauricio Scheffer
@the_drow: I have no idea what your `Fetch()` method does. But if you have a repository abstraction (I'm **not** talking about implementation) using DetachedCriterias and you need to reuse that same abstraction for something other than NHibernate you're basically SOL.
Mauricio Scheffer
@Mauricio Scheffer: I have multiple types of Repositories. One of them depeands on DetachedCriteria. If I inherit from IQueryable I don't really need a Fetch() function right? But then if I get a DetachedCriteria as the parameter I do need the Fetch() function.So how do I create a uniform interface?
the_drow