1
votes

I have an entity that is mapped (using Fluent Nhibernate) to a view in the database.
The view has many columns, but the user can choose the columns that he wants to see in a report. I would like the resulting database query to only contain those columns, for performance reasons.
I think this can be done using QueryOver<>, as explianed here: How to select only a few columns in my NHibernate query?
The problem is that I need to obtain an Iqueryable for paging and sorting, so I am using the Linq Session.Query<> extension method.
I either need a way to convert the QueryOver to an IQueryable or to apply the projection directly to the IQueryable. As the columns to select are dynamic, I cannot create a new entity class or a new mapping.
Thanks

1
Could you check this. The basic projection with NHiberante IQueryable implementation should be working out of the boxRadim Köhler
The problem is that I have the list of columns to show as a list of string and I don't know how to use that list in the IQueryable SelectGuillermo Vasconcelos
This is the best for Criteria API and the Projections using strings. With IQueryable you would have to create your own Expression builders... pretty challenging but not so hard. Anyhow, string constants to property names === the best is Criteria APIRadim Köhler

1 Answers

0
votes

Do you really need to use LINQ? If so, check out System.Linq.Dynamic NuGet package, which is based on Microsoft code. I wrote some posts on that which may help you, see for example: Dynamic Linq Extension Method. You could do better with Criteria or HQL, though.