Actually, after several tweaks, I think I finally got it. Here's what
I came up with:
_sessionFactory = Fluently
.Configure()
.Database
(
MsSqlConfiguration
.MsSql2005
.ConnectionString(c => c.FromConnectionStringWithKey
("conn"))
)
.Mappings( x =>
{
x.FluentMappings
.AddFromAssembly(Assembly.LoadFrom(blah blah...))
.ConventionDiscovery.AddFromAssemblyOf<blah blah...>();
})
.ExposeConfiguration( x =>
{
x.SetProperty("current_session_context_class",
"thread_static");
})
.BuildConfiguration()
.BuildSessionFactory();
It's all clear to me now...thank you to all that replied. Hopefully,
this post helps others out there.
On Mar 31, 6:54 pm, Action Jackson <[email protected]> wrote:
> Hey, thank you very much for your response. However, your
> suggestion to use ExposeConfiguration() doesn't seem to be working
> either. I've tried variations of potential solutions that use
> ExposeConfiguration(). Still no luck. Would you be kind enough to
> provide the full block of code that works for you? I'm still noticing
> the "property count reduction".
>
> On Mar 31, 1:55 pm, epitka <[email protected]> wrote:
>
>
>
> > Did you try ExposeConfiguration like this ?
>
> > _sessionFactory = Fluently
> > .Configure(_cfg)
> > .ExposeConfiguration(c=>c.SetNamingStrategy
> > ( naming strategy class here)
> > .SetProperty("thread_static");
>
> > > .Database
> > > (
> > > MsSqlConfiguration.MsSql2005
> > > .ConnectionString(c =>
> > > c.FromConnectionStringWithKey("conn"))
> > > )
> > > .Mappings
> > > (
> > > x => x.FluentMappings
> > > .AddFromAssembly(...blah blah blah...)
> > > )
> > > .BuildSessionFactory();
>
> > On Mar 31, 1:37 pm, Action Jackson <[email protected]> wrote:
>
> > > Paul and James, thank you very much for your responses. I have
> > > tried these approaches, but with no luck. I'm noticing an issue that
> > > is very interesting. Hopefully, something jumps out at you right
> > > away. Here's an example of the code which presides in a class I call
> > > 'NHibernateHelper' (borrowed from NH in Action):
>
> > > _cfg = new Configuration()
> > > .SetNamingStrategy( naming strategy class here)
> > > .SetProperty("current_session_context_class",
> > > "thread_static");
>
> > > // NOTE: At this point, the _cfg configuration object has 8 properties
> > > including the current session context setting. The interesting part
> > > comes next:
>
> > > _sessionFactory = Fluently
> > > .Configure(_cfg)
> > > .Database
> > > (
> > > MsSqlConfiguration.MsSql2005
> > > .ConnectionString(c =>
> > > c.FromConnectionStringWithKey("conn"))
> > > )
> > > .Mappings
> > > (
> > > x => x.FluentMappings
> > > .AddFromAssembly(...blah blah blah...)
> > > )
> > > .BuildSessionFactory();
>
> > > After executing this piece of logic, the number of properties of the
> > > _cfg configuration object has been reduced from 8 to 5 and the session
> > > context setting is gone. Consequently, a piece of logic like this
> > > fails since there is no session context:
>
> > > try
> > > {
> > > using (ISession session =
> > > NHibernateHelper.GetCurrentSession())
> > > {
> > > using (session.BeginTransaction())
> > > {
> > > CurrentSessionContext.Bind(session);
>
> > > session.Save(person);
> > > }
> > > }
> > > }
> > > finally
> > > {
> > > CurrentSessionContext.Unbind
> > > (NHibernateHelper.SessionFactory);
> > > }
>
> > > Any ideas? Thanks again for your help thus far!
>
> > > On Mar 31, 6:21 am, James Gregory <[email protected]> wrote:
>
> > > > If you're using Fluently.Configure there's also a Raw method, which'll
> > > > allow
> > > > you to set any property that isn't already exposed.
>
> > > > On Tue, Mar 31, 2009 at 12:17 PM, Paul Batum <[email protected]>
> > > > wrote:
> > > > > You set this on your NHibernate.Cfg.Configuration instance right?
>
> > > > > You should be able to use the ExposeConfiguration method to get
> > > > > access to
> > > > > the underlying Configuration instance and then set the session context
> > > > > appropriately. Or alternatively you can build your Configuration
> > > > > instance as
> > > > > you normally would including setting the session context, and then
> > > > > pass it
> > > > > in as an argument to Fluently.Configure().
>
> > > > > Paul Batum
>
> > > > > On Mon, Mar 30, 2009 at 2:56 PM, Action Jackson
> > > > > <[email protected]>wrote:
>
> > > > >> I apologize in advance if this question has been answered many times
> > > > >> over. How can I specify the session context using the Fluent
> > > > >> configuration? In other words, what is the Fluent translation of a
> > > > >> traditional xml mapping like "<property
> > > > >> name="current_session_context_class">thread_static</property>"?-
> > > > >> Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---