Question

I am coding a screen which includes a list of items. Each item includes a button where the user can popup a dialog to enter or read (their previously entered) feedback on said line item. Because feedback contains a substantial amount of textual data and there may be many line items per page I am using AJAX to load feedback on demand.

I would like to have a different icon for the line item's feedback button depending on whether or not the user has left feedback. The goal is to make users aware of what is yet to be entered. I am using NHibernate as my ORM. Is it possible to write an NHibernate query that includes a boolean value indicating whether a database column is null or not? Otherwise is it possible to return the string length for each row, again using NHibernate? I'm using the Criteria API, but any help would be appreciated.

Essentially I am trying to do this:

SELECT id, name, has_feedback is null as has_preview FROM my_table;
Was it helpful?

Solution

it is possible to get the string length using nhibernate functions

session.QueryOver<Foo>()
    .Select(Projections.SqlFunction("length", NHibernateUtil.Int32, Projections.Property<Foo>(foo => foo.Name)))
    .List();

session.CreateCriteria<Foo>()
    .SetProjection(Projections.SqlFunction("length", NHibernateUtil.Int32, Projections.Property(Name)))
    .List<int>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top