NHibernate 2.0:Cfg.Configuration.SetProperties Problema con IDictionary
-
20-08-2019 - |
Pregunta
Tengo un problema con:
NHibernate.Cfg.Configuration.SetProperties()
No aceptar el IDiccionario:NHibernateConfigHandler
Recibo los mensajes:
Error 30 La mejor coincidencia de método sobrecargado para 'NHibernate.Cfg.Configuration.SetProperties(System.Collections.Generic.IDictionary)' tiene algunos argumentos no válidos
y
Error 31 Argumento '1':no se puede convertir de 'System.Collections.IDictionary' a 'System.Collections.Generic.IDictionary'
¿Por favor avise?
Todo el método:
/// <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;
}
Solución
La firma de SetProperties es
public NHibernate.Cfg.Configuration SetProperties(System.Collections.Generic.IDictionary<string,string> newProperties)
Member of NHibernate.Cfg.Configuration
Setproperties está tomando parámetros de tipo IDictionary, es decir, Diccionario genérico. Y estás tratando de pasar en IDictionary. Esa es la razón del error.
Puede cambiar el tipo de Propiedades en NHibernateConfigHandler a System.Collections.Generic.IDictionary. O Cree un System.Collections.Generic.IDictionary y copie todos los valores de System.Collections.IDictionary.
Siempre es eficiente usar Diccionario genérico (que está en System.Collections.Generic) sobre IDictionary (que está en System.Collections).