Getting single column from an entity
c#, nhibernate
Solution
Here is the solution I eventually ended up using:
ICriteria c = session.CreateCriteria(typeof(Tribble));
c.SetProjection(Projections.ProjectionList().Add(Projections.Property("Name")));
IList<string> names = c.List<string>();
I got this idea from this old StackOverflow question.
Problem
How can you get a single column back from a query instead of a whole object? I could do something like this to get the whole object, but all I want is the names: ``` IList<Tribble> tribbles = session.CreateCriteria(typeof(Tribble)).List<Tribble>(); IList<string> names = new List<string>(); foreach (Tribble t in tribbles) { names.Add(t.Name); } ``` I would like to be able to specify additional criteria, so is it possible to just exclude certain columns from being retrieved?