Every public member (props, methods, etc.) on your persistent entities must be marked virtual in order for NH to guarantee the proper behavior of its lazy-loading proxy when you interact with it. This includes any unmapped public API members (props, etc.). The error about 'no session is available for...' is almost certainly unrelated to the mapping, instead its probably about your session-management approach.
The correct approach should be to make the prop virtual but not to map it (if its in fact not a persistent value for the entity). I'd look carefully at how/where you're managing your session lifecycle in order to troubleshoot the "no session is available for.." underlying error. Hope this helps, -Steve B. On Monday, April 23, 2012 2:04:05 PM UTC-4, s-stude wrote: > > Fran, thank you foy your response. > > I agree that I don't need to map it, but I have an error > --- NHibernate.LazyInitializationException: > Initializing[Core.Entities.Topic#1]-failed to lazily initialize a > collection of role: Core.Entities.Topic.Votes, no session or session > was closed > > If I remove the virtual keyword from this readonly property I get an > error like this > --- The following types may not be used as proxies: > Core.Entities.Topic: method get_VotedUpCount should be 'public/ > protected virtual' or 'protected internal virtual' > > > On Apr 23, 8:40 pm, Fran Knebels <[email protected]> wrote: > > Why map it at all? The point of the mapping is to map domain properties > to > > table columns. If this is just a convenience method for your domain > layer, > > you shouldn't have to map it all. > > > > > > > > > > > > > > > > On Monday, April 23, 2012, s-stude wrote: > > > Hi. > > > > > I'm using Nhibernate 3.2.0.4000 and FluentNHibernate 1.3.0.717. > > > > > I have next Entity > > > > > public class Topic : EntityBase > > > { > > > private readonly ICollection<Vote> _votes; > > > > > public virtual string Title { get; protected set; } > > > public virtual User CreatedBy { get; protected set; } > > > public virtual ICollection<Vote> Votes > > > { > > > get { return _votes; } > > > } > > > > > public virtual int VotedUpCount > > > { > > > get > > > { > > > return _votes.Count(v => v.VotedTo == > > > VoteType.VoteUp); > > > } > > > } > > > > > // .... > > > } > > > > > I need to map VotedUpCount because I get an error. But I don't need > > > this column in my table. I just want to get real-world domain entity. > > > > > I tried this one: > > > > > public class TopicMap : ClassMap<Topic> > > > { > > > public TopicMap() > > > { > > > Id(x => x.Id); > > > Map(x => x.Title); > > > Map(x => x.VotedUpCount).Access.ReadOnly(); > > > Map(x => x.VotedDownCount).Access.ReadOnly(); > > > References(x => x.CreatedBy); > > > HasMany<Vote>(x => x.Votes) > > > .Cascade.All(); > > > } > > > } > > > > > But I recieve an error Invalid column name 'VotedUpCount'. > > > Is there any way to map it in the proper way? > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "nhusers" group. > > > To post to this group, send email to > > > [email protected]<javascript:;> > > > > . > > > To unsubscribe from this group, send email to > > > [email protected] <javascript:;>. > > > 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 view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/NpRziEnVRuEJ. 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.
