Hi Richard, thank you for reply and hints. This will certainly help :) regards, Kamil Kliczbor
On 17 Sty, 17:55, "Richard Brown \(gmail\)" <[email protected]> wrote: > Hi Kamil, > > Unfortunately QueryOver cannot statically type the strings inside a > SqlProjection ... but they can accept IProjection instances (to allow, > amongst other things, private property access). So you could write: > > ProductDescriptionDto dtoAlias = null; > var dto = > s.QueryOver<Product>() > .SelectList(builder => builder > .Select(p => p.Name).WithAlias(() => dtoAlias.ProductName) > .Select(roundSqlProjection)) > > .TransformUsing(Transformers.AliasToBean(typeof(ProductDescriptionDto))) > .List<ProductDescriptionDto>(); > > Hope that helps a little. > > Richard > > -----Original Message----- > From: kamil.kliczbor > Sent: Saturday, January 15, 2011 4:59 PM > To: nhusers > Subject: [nhusers] Is there any SqlProjection counterpart in QueryOver? > > Helo, > when i have CriteriaAPI: > public class ProductDescriptionDto > { > public string ProductName { get; set; } > public decimal ProductsPrice { get; set; } > } > > IProjection roundSqlProjection = > Projections.SqlProjection(@"round(UnitPrice * UnitsInStock, -2) as > ProductsPrice", > new string[] > { "ProductsPrice" }, > new IType[] > { NHibernateUtil.Decimal }); > > this.Session.CreateCriteria(typeof(Product)) > .SetProjection(Projections.ProjectionList() > > .Add(Projections.Property("Name").As("ProductName")) > .Add(roundSqlProjection)) > > .SetResultTransformer(Transformers.AliasToBean(typeof(ProductDescriptionDto))) > .List<ProductDescriptionDto>(); > it does what it deos. > I wanted to make it work under QueryOver. I tired but ther eis not > such "SelectSqlProjection" or something in the Selectlist builder. > > It tried like this below but it gives me an error: > Unrecognised method call in epression > Round((x.UnitPrice.GetValueOrDefault() * Convert(x.UnitsInStock))). > > And the query goes like this: > this.Session.QueryOver<Product>() > .SelectList(builder => builder > .Select(x => x.Name).WithAlias(() => > dtoAlias.ProductName) > .Select(x => > Math.Round(x.UnitPrice.GetValueOrDefault() * > x.UnitsInStock)).WithAlias(() => dtoAlias.ProductsPrice)) > > .TransformUsing(Transformers.AliasToBean(typeof(ProductDescriptionDto))) > .List<ProductDescriptionDto>(); > > Is there support for SqlProjections in QueryOver or workaround for > this? > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/nhusers?hl=en. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
