Swings and roundabouts regarding preferred solution.
IMO as soon as you expose a property then other developers will want to always use the property in the WHERE clause rather than relying on the beauty of NHibernate. However if the property is a enum/int/char(1) then I totally agree. Although as always this is always open to debate J Thanks for answers guys From: [email protected] [mailto:[email protected]] On Behalf Of Gunnar Liljas Sent: 29 August 2011 22:16 To: [email protected] Subject: Re: [nhusers] Re: Getting discriminator value using Linq when using DTO's Not only is it a good workaround, but I'd say it'd the preferred solution. If the (name of the) type really has relevance, it deserves a property. /G 2011/8/29 [email protected] <[email protected]> There would have to be an additional nhlinq function to accomplish this & at current, there isn't. A super easy workaround is to just map the discriminator as a readonly property and select that property directly. cm.Property(x => x.DiscrimType, x => { x.Column("DiscriminatorType"); x.Insert(false); x.Update(false); }); On Aug 27, 1:24 am, Richard Wilde <[email protected]> wrote: > When projecting a discriminator column into a DTO using QueryOver I > can do the following:- > > return Session > .QueryOver<Product>() > .SelectList(i => i > .Select(p => p.Name).WithAlias(() => dto.Name) > .Select(p => p.GetType()).WithAlias(() => dto.ProductType) > ) > .TransformUsing(Transformers.AliasToBean<ProductDto>()) > .List<ProductDto>(); > > However when using Linq I can't seem to get the discriminator value > only the derived class name. > > return (from product in Session.Query<Product>() > select new ProductDto{ > Name = product.Name, > ProductType = product.GetType().Name > > }).ToList(); > > Here GetType().Name returns the derived class name (as one would > expect), how do I get the discriminator value using Linq? -- 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] <mailto:nhusers%[email protected]> . For more options, visit this group at http://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. -- 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.
