English 中文(简体)
• 如何将沙普阿奇侦察和恩赫特混为一谈。 通过流体进行搜索。 NHibernate. 搜查?
原标题:How can integrate SharpArchitecture and NHibernate.Search via Fluent.NHibernate.Search?

I m trying to use NHibernate.Search on a SharpArchitecture app, with FluentNHibernate.Search mapping to maintain pure POCO domain objects.

但是,我知道如何建立NHibernateSession:

在我的全球会议上 i) 具备这种初步化和工作标准:

NHibernateSession.Init(
    this.webSessionStorage,
    new[] { Server.MapPath( "~/bin/MyBlog.Infrastructure.dll" ) },
    new AutoPersistenceModelGenerator().Generate(),
    Server.MapPath( "~/NHibernate.config" ) );

然后, 说,需要像这样建立流层:

Configuration nhcfg = FluentSearch.Configure()
    .DefaultAnalyzer().Standard()
    .DirectoryProvider().FSDirectory()
    .IndexBase("~/Index")
    .IndexingStrategy().Event()
    .MappingClass<LibrarySearchMapping>()
    .BuildConfiguration();

最后,NHibernate被没收。 • 搜索流体。

但是,可以把“nhcfg”与NHibernateSession混为一谈。 Init? NHibernateSession. Init and FluentHibernate. 搜查似乎有不相容的接口。

是否有办法将NHibernate合并。 • 寻找液态的沙普阿奇探测仪。 搜索绘图?

最佳回答

Solved!

我从SharpArchitecture处研究了NHibernateSesssion的执行情况,并从NHibernateSession外提取了车间配置。 惯用方法。 最后,我增加了名为NHibernateSession的新组合。 添加配置方法。

Pay attention that NHibernateSession.Init internally register some listeners:

 c.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[]
                        {
                            new DataAnnotationsEventListener()
                        };
 c.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[]
                        {
                            new DataAnnotationsEventListener()
                        };

问题是,SharpArch是内部数据发布。 NHibernate.dll;因此,我需要在项目内重复这一类别。 只是工作。

最后,国家自由会议初步确定如下:

        var nhConfig = new Configuration();
        nhConfig.Configure( Server.MapPath( "~/NHibernate.config" ) );

        var cnf = Fluently
            .Configure( nhConfig )
            .Mappings( 
                m =>
                   {
                       var mappingAssembly = Server.MapPath( "~/bin/MyBlog.Infrastructure.dll" );
                       var assembly = Assembly.LoadFrom( MakeLoadReadyAssemblyName( mappingAssembly ) );
                       m.HbmMappings.AddFromAssembly( assembly );
                       m.FluentMappings.AddFromAssembly( assembly ).Conventions.AddAssembly( assembly );

                       m.AutoMappings.Add( new AutoPersistenceModelGenerator().Generate() );                   
                   })
            .ExposeConfiguration( c =>
                {   
                    FluentSearch.Configure( c )
                        .DefaultAnalyzer().Standard()
                        .DirectoryProvider().FSDirectory()
                        .IndexBase( "~/Index" )
                        .IndexingStrategy().Event()
                        .Listeners( FluentNHibernate.Search.Cfg.ListenerConfiguration.Default )
                        .MappingClass<SearchMap>()
                        .BuildConfiguration();

                    c.SetListeners( ListenerType.PostInsert, new[] { new FullTextIndexEventListener() } );
                    c.SetListeners( ListenerType.PostUpdate, new[] { new FullTextIndexEventListener() } );
                    c.SetListeners( ListenerType.PostDelete, new[] { new FullTextIndexEventListener() } );

                    c.SetListener( ListenerType.PostCollectionRecreate, new FullTextIndexCollectionEventListener() );
                    c.SetListener( ListenerType.PostCollectionRemove, new FullTextIndexCollectionEventListener() );
                    c.SetListener( ListenerType.PostCollectionUpdate, new FullTextIndexCollectionEventListener() );

                    /*
                    c.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[]
                        {
                            new DataAnnotationsEventListener()
                        };
                    c.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[]
                        {
                            new DataAnnotationsEventListener()
                        };
                   */
                })
            .BuildConfiguration();

        NHibernateSession.Storage = this.webSessionStorage;

        NHibernateSession.AddConfiguration(
            NHibernateSession.DefaultFactoryKey,
            cnf.BuildSessionFactory(),
            cnf,
            null);
问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签