3

I'm working on a CQRS-style system with commands processed with NSericeBus and queries provided through a read-only OData feed.

We would like to have the WCF Data Services feed backed by NHibernate so we can have control over how our data appears in the feed (calculated fields, etc), which the Entity Framework provider does not allow.

However, using the reflection provider with Linq to NHibernate, we are getting errors when we navigate to related entities (e.g, http://server/feed/Foo(1)/Bar).

Has anyone made a Linq to NHibernate backed WCF Data Service work?

Eric Farr
  • 2,683
  • 21
  • 30

2 Answers2

0

Most like what you're looking for is NHibernate.OData. This allows you to take the passed in odata and have NHibernate auto-convert it to a DetachedCriteria instance.

Justin
  • 17,670
  • 38
  • 132
  • 201
  • Justin, I was trying to go the other way... creating an oData feed from NHibernate. I'm no longer using oData or NHibernate (RavenDB instead), and life is much better! – Eric Farr May 17 '12 at 20:21
0

How do you mean, you want to do something that the Entity Framework does not allow?

If you need calculated fields, you can define a View in your DB (SQL Server?) with calculated fields, and incorporate that View into your read-only Entity Model.

If you need to pre-calculate the fields, you can simply do that in your denormalizer code.

What scenario do you need that you cannot do with EF?

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76
  • Roy, imagine a table with a column called ‘Duration’ that corresponds to a C# TimeSpan. Its value is stored in the database as ticks (one ten-millionth of a second, not very user friendly). I would like to present a column called ’DurationInMinutes’ that converts Duration into minutes. – Eric Farr May 24 '11 at 13:16
  • You can do that easily in a View. Your View would then contain something like SELECT X, Y, Duration / (60 * 10 * 1e6) AS DurationInMinutes, Z FROM ... And then you can query your View just like you would a real table. – Roy Dictus May 24 '11 at 13:20