2009-05-10 7 views
0

J'ai un problème avec:NHibernate 2.0: Problème avec Cfg.Configuration.SetProperties IDictionary

NHibernate.Cfg.Configuration.SetProperties() 

Ne pas accepter IDictionary: NHibernateConfigHandler

-je obtenir les messages:

Erreur 30 Le meilleur la méthode surchargée correspond à 'NHibernate.Cfg.Configuration.SetProperties (System.Collections.Generic.IDictionary)' a des arguments non valides

et

Erreur 31 Argument '1': ne peut pas convertir 'System.Collections.IDictionary' à 'System.Collections.Generic.IDictionary'

S'il vous plaît conseiller?


Toute méthode:

/// <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; 

}

Répondre

1

Signature du SetProperties est

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

setProperties prend des paramètre de type IDictionary, i.e. générique Dictionnaire. Et vous essayez de passer en IDictionary. C'est la raison de l'erreur.

Soit vous pouvez changer le type de propriétés dans NHibernateConfigHandler à System.Collections.Generic.IDictionary. OU Créez un System.Collections.Generic.IDictionary et copiez toutes les valeurs à partir de System.Collections.IDictionary.

Il est toujours efficace d'utiliser le dictionnaire générique (qui est sur System.Collections.Generic) sur IDictionary (qui est sur System.Collections).

Questions connexes