0

我有一个问题:

NHibernate.Cfg.Configuration.SetProperties()

不接受 IDictionary:NHibernateConfigHandler

我收到以下消息:

错误 30 'NHibernate.Cfg.Configuration.SetProperties(System.Collections.Generic.IDictionary)' 的最佳重载方法匹配有一些无效参数

错误 31 参数“1”:无法从“System.Collections.IDictionary”转换为“System.Collections.Generic.IDictionary”

请指教?


整个方法:

/// <param name="config">NHibernate configuration</param>
public ISessionFactory GetSessionFactoryFor(NHibernateConfigHandler config)
{
if (config == null)
    throw new ArgumentNullException("config may not be null nor empty");

ISessionFactory sessionFactory = GetSessionFactoryFor(config.MappingAssembly);

//  Failed to find a cached SessionFactory so make a new one.
if (sessionFactory == null)
{
    NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();

    cfg.SetProperties(config.Properties); //THIS LINE

    cfg.AddAssembly(config.MappingAssembly);

    //  Now that we have our Configuration object, create a new SessionFactory
    sessionFactory = cfg.BuildSessionFactory();

    if (sessionFactory == null)
    {
        throw new InvalidOperationException("cfg.BuildSessionFactory() returned null.");
    }

    HttpRuntime.Cache.Add(config.MappingAssembly, sessionFactory, null, DateTime.Now.AddDays(7),
        TimeSpan.Zero, CacheItemPriority.High, null);
}

return sessionFactory;

}

4

1 回答 1

1

SetProperties 的签名是

public NHibernate.Cfg.Configuration SetProperties(System.Collections.Generic.IDictionary<string,string> newProperties)
    Member of NHibernate.Cfg.Configuration

Setproperties 采用IDictionary 类型的参数,即通用字典。而你试图传入 IDictionary。这就是错误的原因。

您可以将 NHibernateConfigHandler 中的属性类型更改为 System.Collections.Generic.IDictionary。或创建 System.Collections.Generic.IDictionary 并从 System.Collections.IDictionary 复制所有值。

使用通用字典(在 System.Collections.Generic 上)而不是 IDictionary(在 System.Collections 上)总是很有效。

于 2009-05-10T14:29:16.313 回答