“在配置中找不到方言”流畅的休眠

发布于 2024-11-16 04:30:41 字数 940 浏览 0 评论 0原文

我在 ASP.net MVC 3.0 项目中使用 Fluent Nhibernate 和 MSSql 2008。

 
private static ISessionFactory CreateSessionFactory()
        {
 FluentConfiguration configuration = Fluently.Configure()
     .Database(MsSqlConfiguration.MsSql2008
       .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true")
       .ShowSql()).ExposeConfiguration(c => c.SetProperties(AddProperty()))
     .Mappings(m => m
       .FluentMappings.AddFromAssemblyOf());
       return configuration.BuildSessionFactory();
}

private static IDictionary  AddProperty()
        {
            IDictionary config = new Dictionary();
            config.Add("current_session_context_class", "web");
            config.Add(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
            return config;
        }
 

但是,我收到此错误“在配置中找不到方言”

I am using Fluent Nhibernate with MSSql 2008 in an ASP.net MVC 3.0 project.

 
private static ISessionFactory CreateSessionFactory()
        {
 FluentConfiguration configuration = Fluently.Configure()
     .Database(MsSqlConfiguration.MsSql2008
       .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true")
       .ShowSql()).ExposeConfiguration(c => c.SetProperties(AddProperty()))
     .Mappings(m => m
       .FluentMappings.AddFromAssemblyOf());
       return configuration.BuildSessionFactory();
}

private static IDictionary  AddProperty()
        {
            IDictionary config = new Dictionary();
            config.Add("current_session_context_class", "web");
            config.Add(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
            return config;
        }
 

But, I am getting this error "Could not find the dialect in the configuration"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤单情人 2024-11-23 04:30:41

您实际上正在覆盖所有先前配置步骤设置的所有属性。尝试添加到集合中:

private static ISessionFactory CreateSessionFactory()
{
    FluentConfiguration configuration = Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true")
            .ShowSql())
        .ExposeConfiguration(AddProperties)
        .Mappings(m => m
            .FluentMappings.AddFromAssemblyOf());

    return configuration.BuildSessionFactory();
}

private static IDictionary  AddProperties(NHibernate.Cfg.Configuration config)
{
    config.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, "web");
    config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
    return config;
}

You are actually overwriting all the properties that have been set by all previous configuration steps. Try adding to the collection instead:

private static ISessionFactory CreateSessionFactory()
{
    FluentConfiguration configuration = Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true")
            .ShowSql())
        .ExposeConfiguration(AddProperties)
        .Mappings(m => m
            .FluentMappings.AddFromAssemblyOf());

    return configuration.BuildSessionFactory();
}

private static IDictionary  AddProperties(NHibernate.Cfg.Configuration config)
{
    config.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, "web");
    config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
    return config;
}
冷血 2024-11-23 04:30:41

您可以尝试这样的事情

FluentConfiguration configuration = Fluently.Configure()
                            .Database(MsSqlConfiguration.MsSql2008
                            .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true")
                            .ShowSql().Dialect("NHibernate.Dialect.MsSql2008Dialect")).ExposeConfiguration(c => c.SetProperties(AddProperty()))
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf());

另外对于 WebSessionContext,您可以使用此代码

FluentConfiguration configuration = Fluently.Configure()
                            .Database(MsSqlConfiguration.MsSql2008
                            .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true").CurrentSessionContext<WebSessionContext>()
                            .ShowSql().Dialect("NHibernate.Dialect.MsSql2008Dialect"))

You could try something like this

FluentConfiguration configuration = Fluently.Configure()
                            .Database(MsSqlConfiguration.MsSql2008
                            .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true")
                            .ShowSql().Dialect("NHibernate.Dialect.MsSql2008Dialect")).ExposeConfiguration(c => c.SetProperties(AddProperty()))
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf());

Also for the WebSessionContext, you could use this code

FluentConfiguration configuration = Fluently.Configure()
                            .Database(MsSqlConfiguration.MsSql2008
                            .ConnectionString("Data Source=Comp;Initial Catalog=MyDB;Integrated Security=true").CurrentSessionContext<WebSessionContext>()
                            .ShowSql().Dialect("NHibernate.Dialect.MsSql2008Dialect"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文