1

I am working on a WCF project, which provides business information out of several data sources. To reuse the code, my BusinessContactService contains a generic repository dependency defined as:

public interface IRepository<T> {
   IQueryable<T> Find(Expression<Func<T, bool>> criteria);
} 

And service queries data source via repository as:

repo.Find(b => b.Name.Contains("abc"));

When the data source is a sql server database, it works via Entity Framework. But when the service runs on an Ingres database, it comes a problem because its .NET data provider or ODBC driver doesn't work with LINQ expression. The following are some workarounds I've found:

  1. Virtuoso data provider for EF: As it isn't free and system team don't feel like install it anyway, I can't use it.
  2. Customize an Ingres EF provider as Entity Framework sample provider shows. It is quite interesting, but I am afraid not make the timeline (by next week!)
  3. Hiding the usage of LINQ expression in my service by using specification pattern. Therefore still use LINQ in sql server specifications implementation, while use ado.net for Ingres case.
  4. NHibernate.Linq. I know little on NHibernate, but someone here said it works fine with ODBC and I guess it may be able to bridge LINQ expression with Ingres.

Please give suggestions on option 2 - 4. Many Thanks!

Community
  • 1
  • 1
tang
  • 13
  • 3

1 Answers1

1

First of all, a little suggestion. For your generic interfece, I think it would be better to expose:

IQueryable<T> Query<T>();

So the application layer will be able to call it and chain whatever it wants, like:

var temp = repo.Query<User>().Where(c => c.Email.Contains("@foo.com")).OrderBy(c => c.FirstName);

For your question, I found out that, when there isn't an EF provider - or you can't use it for any reason - NHibernate with Fluent Nhibernate are quite the alternative. Not as powerful as EF (code first, obviously) but still a good fallback. It supports the most common linq operators and it will fit perfectly in your abstracted design.

Matteo Mosca
  • 7,380
  • 4
  • 44
  • 80
  • Thanks, Matteo. I like the Query() method. Generic the method instead of class, doesn't it? And I will try NHibernate. – tang Jun 29 '11 at 09:28
  • Yes. Your repository interface shouldn't be generic. You implement it in one single class, then through Query you can access all your types. – Matteo Mosca Jun 29 '11 at 09:36