The domain object: public class Topic { public virtual int Id { get; protected set; } public virtual string Title { get; set; } public virtual DateTime Created { get; set; } public virtual int DisplayPriority { get; set; } public virtual Forum Forum { get; set; } public virtual int PostCount { get; protected set; } }
and the mapping override: public class TopicMapper : IAutoMappingOverride<Topic> { public void Override(AutoMapping<Topic> mapping) { mapping.Table("forumTopics"); mapping.References(t => t.Forum).Not.Nullable(); mapping.Map(t => t.PostCount).Formula("(SELECT COUNT(*) FROM forumPosts p where p.TopicID = Id)"); } } On Oct 12, 1:41 pm, Paul Batum <paul.ba...@gmail.com> wrote: > Can you post your domain object and the mapping override for it? > I figure something else has to be screwing up the result of the formula. > > On Mon, Oct 12, 2009 at 4:06 PM, Schlaefisch > <schlaefi...@googlemail.com>wrote: > > > > > The exact query results in a syntax error, when I replace "this_.Id = > > @p0;@p0 = 1" with "this_.Id = 1" the result is correct. > > > But even when I use "SELECT 5" as formula, the PostCount is still 0. > > > On Oct 6, 1:16 pm, Paul Batum <paul.ba...@gmail.com> wrote: > > > Off the top of my head, I can't see anything wrong with your mapping. > > I've > > > used formula columns with automapping for similar purposes without > > problems. > > > Have you executed that generated query against the db and confirmed that > > it > > > returned the correct results? > > > > On Fri, Oct 2, 2009 at 9:06 AM, Schlaefisch <schlaefi...@googlemail.com > > >wrote: > > > > > Update: The Console Output. > > > > > Manual SQL: > > > > NHibernate: (SELECT COUNT(*) FROM forumPosts p where p.TopicID = 1) > > > > Mapping SQL: > > > > NHibernate: SELECT top 2 this_.Id as Id0_0_, this_.Title as Title0_0_, > > > > this_.Created as Created0_0_, this_.DisplayPriority as DisplayP4_0_0_, > > > > this_.ForumID as ForumID0_0_, (SELECT COUNT(*) FROM forumPosts p where > > > > p.TopicID = this_.Id) as formula0_0_ FROM forumTopics this_ WHERE > > > > this_.Id = @p0;@p0 = 1 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---