I'm trying to generate SQL along the lines of:
SELECT
t.*,
SELECT (...)
FROM Title t
[trimmed]
using QueryOver
Title title = null;
var q = session
.QueryOver(() => title)
.Select(
Projections.Alias(Projections.Property<Title>(t => t.Id), "Id"),
Projections.Alias(Projections.Property<Title>(t => t.Name), "Name"),
....
Projections.SubQuery(sq.Where(tt => tt.Id == title.Id))), "TopLevelGenre")
)
[code trimmed]
There are 15 properties in Title that I would like to project. Is there an easier way of doing it so that I don't have to project each property individually as I've started to do above?
If you don't mind ICriteria, this works. I have tested with 2.1.2, but I can't see why if wouldn't work with 3.x.
var projectionList = Projections.ProjectionList();
var metadata = session.SessionFactory.GetClassMetadata(typeof(Title));
foreach (var name in metadata.PropertyNames)
{
projectionList.Add(Projections.Property(name), name);
}
var criteria = DetachedCriteria.For<Title>()
.SetProjection(projectionList)
...;
I've discovered that as of NHibernate 3.2, this is not possible without manually enumerating all of the properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With