2009-05-10 3 views
0

Ich habe ein Problem mit:NHibernate 2.0: Cfg.Configuration.SetProperties Ausgabe mit IDictionary

NHibernate.Cfg.Configuration.SetProperties() 

Nicht die IDictionary akzeptieren: NHibernateConfigHandler

bekomme ich die Nachrichten:

Fehler 30 Der beste Überladene Methodenübereinstimmung für 'NHibernate.Cfg.Configuration.SetProperties (System.Collections.Generic.IDictionary)' hat einige ungültige Argumente

und

Fehler 31 Argument '1': aus 'System.Collections.IDictionary' auf 'System.Collections.Generic.IDictionary'

Bitte geben Sie nicht konvertieren?


Die ganze Methode:

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

}

Antwort

1

Signatur von SetProperties ist

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

SetProperties Parameter vom Typ IDictionary nimmt, das heißt Allgemein Wörterbuch. Und du versuchst IDictionary zu übergeben. Das ist der Grund für Fehler.

Sie können den Typ der Eigenschaften in NHibernateConfigHandler in System.Collections.Generic.IDictionary ändern. OR Erstellen Sie ein System.Collections.Generic.IDictionary, und kopieren Sie alle Werte aus System.Collections.IDictionary.

Es ist immer effizient, generisches Dictionary (das sich auf System.Collections.Generic befindet) über IDictionary (das sich auf System.Collections befindet) zu verwenden.

Verwandte Themen