0

I was going through Fluent nhibernate wiki and i know that Fluent nhibernate is built on top of nHibernate... Should i care/have knowledge about nHibernate before choosing Fluent nHibernate? Any suggestion...

ACP
  • 34,682
  • 100
  • 231
  • 371

5 Answers5

2

You absolutely need to learn NHibernate. Fluent NHibernate is only a wrapper over NHibernate's mapping API, and mapping is only a small part of working with NHibernate.

Queries (Criteria/HQL/LINQ), sessions, locking, lazy/eager loading, etc, are concepts that you must know when working with NHibernate and have nothing to do with Fluent NHibernate.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
1

of course, fluent nhibernate is mainly there to make mapping simpler (and type safe)

Jaguar
  • 5,929
  • 34
  • 48
1

I say yes. If you know NHibernate's XML based mapping format, it's much easier to track down errors via fluent NH's [FluentMappingsContainer].ExportTo([e.g. Environment.CurrentDirectory]).

Edit: ASP.NET MVC example w/ StructureMap

StructureMap:

 private static void ConfigureSQLiteInMemoryTest(IInitializationExpression init)
        {
            init.For<ISessionFactory>()
                .Singleton()
                .Use( Fluently.Configure()
                          .Database( SQLiteConfiguration.Standard.InMemory().AdoNetBatchSize( 100 ).ShowSql )
                          .Mappings( m => m.FluentMappings.AddFromAssemblyOf<MyEntity>() )
                          .ExposeConfiguration( config =>
                                                    {
                                                        config.SetProperty( NHEnvironment.ProxyFactoryFactoryClass,
                                                                            typeof( ProxyFactoryFactory ).AssemblyQualifiedName );   

                                                    } )
                          .BuildSessionFactory() );

            init.For<ISession>()
                .LifecycleIs( GetLifecycle() )
                .Use( context =>
                          {
                              var session = context.GetInstance<ISessionFactory>().OpenSession();

                              new TestData( session, _nhConfig ).Create();

                              return session;
                          } );
        }

Tell MVC to use a StructureMap based controller factory:

Global.asax.cs:

protected void Application_Start()
        {
            [...]

            var controllerFactory = new StructureMapControllerFactory( ObjectFactory.Container );

            ControllerBuilder.Current.SetControllerFactory( controllerFactory );

            [...]

        }

public class StructureMapControllerFactory : DefaultControllerFactory
    {
        private readonly IContainer _container;

        public StructureMapControllerFactory( IContainer container )
        {
            _container = container;
        }

        protected override IController GetControllerInstance( RequestContext requestContext, Type controllerType )
        {
            if (controllerType == null)
                return null;

            return (IController)_container.GetInstance( controllerType );
        }
    }
Martin R-L
  • 4,039
  • 3
  • 28
  • 28
  • can i use this for mysql Database instead of sqllite.. What should i do? – ACP Jun 16 '10 at 11:51
  • I guess you can. I've only used NH w/ SQLite, SQLS, and Oracle myself. Try changing the param of the Database(...) method to one that defines MySql. – Martin R-L Jun 16 '10 at 12:36
1

YES!

You will get completely lost if you do not understand at least the basics of NHibernate. NHibernate is a complex tool and fluent NHibernate really only makes working with it more convenient - it does not hide the complexity.

UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
0

Try the answer for this question for tutorials

Where can i find a Fluent NHibernate Tutorial?

It makes sense to have a grasp of NHibernate before you learn fluent nhibernate. As @Jaguar says it sits on top of nhibernate.

It might be worth looking at nhlambdaextensions.googlecode.com - although this is going to be included in the next version!

For Nhibernate tutorials check out dimecasts or tekpub - or nhibernate.info - see question

Learning NHibernate

NHibernate is database agnostic. :)

Community
  • 1
  • 1
Aim Kai
  • 2,934
  • 1
  • 22
  • 34