0

I am new to nHibernate. I understand how to use mapping using Fluent nHibernate. Now I would like to use a little more complex query. However I am not sure how I would map or even approach this. Here is what I would like to do in an sql query:

SELET 
  Zone,
  CountOfStyles = (Select Count(1) from anotherTable Where StoreZoneId = zone.ZoneID),
  ZoneId,
  ZoneTitle,
  ZoneDescription
FROM
  Zones

How would I map this using fluent nHibernate?

1 Answer 1

2

I think this might get you started...

UPDATE:

mapping

Map(x => x.CountOfStyles).Formula("(Select Count(1) from anotherTable Where StoreZoneId = ZoneID)");
Sign up to request clarification or add additional context in comments.

5 Comments

he wants the count to be part of the query for the entity, not to eager load the list of styles just to get the count.
I could do that, but the whole idea to use nhibernate was to get away from views/sprocs. There is no other way? My query is not really complex :)
I got it working. Since both of my fields are called the same in both tables, I did not know exactly how to use the parent field. I just had to add the anotherTable into the where clause. Map(x => x.CountOfStyles).Formula("(Select Count(1) from anotherTable Where anotherTable.StoreZoneId = ZoneID)");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.