nhibernatenhibernate-projections

nHibernate - Dynamic projection list, need to return constant text


How can I return constant text in projection list, Not sure if I am doing it right or not.

projectionList.Add(Projections.Property("This Year Issue Price").WithAlias(() => sProduct.PriceTitle));

This way I assume that I will get "This Year Issue Price" as columns value for PriceTitle. Doing it because this is dynamic and could be different name and value on conditions.

Thanks


Solution

  • To return constant, we can use Projections.Constant() methods:

    // Projections.Property("This Year Issue Price").WithAlias(() => sProduct.PriceTitle)
    Projections.Constant("This Year Issue Price").WithAlias(() => sProduct.PriceTitle)
    

    NOTE: But, there really should be some reason, for this, because we send that value to DB, then recieve it as many times as many records we get.

    Maybe easier way, is to applly some expost processing on app server (in C#)