NHibernate 2.0: Cfg.Configuration.SetProperties Ausgabe mit IDictionary
-
20-08-2019 - |
Frage
Ich habe ein Problem mit:
NHibernate.Cfg.Configuration.SetProperties()
Nicht die Annahme des IDictionary: NHibernateConfigHandler
Ich erhalte die Nachrichten:
Fehler 30 Die beste überladene Methode Spiel für 'NHibernate.Cfg.Configuration.SetProperties (System.Collections.Generic.IDictionary)' hat einige ungültige Argumente
und
Fehler 31 Argument '1': Konvertierung von 'System.Collections.IDictionary' auf 'System.Collections.Generic.IDictionary'
Bitte geben Sie?
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;
}
Lösung
Signatur von SetProperties ist
public NHibernate.Cfg.Configuration SetProperties(System.Collections.Generic.IDictionary<string,string> newProperties)
Member of NHibernate.Cfg.Configuration
SetProperties nimmt Parameter vom Typ IDictionary, das heißt Allgemein Wörterbuch. Und Sie versuchen, in IDictionary passieren. Das ist der Grund für Fehler.
Sie können entweder Art von Immobilien in NHibernateConfigHandler zu System.Collections.Generic.IDictionary ändern. ODER Erstellen Sie eine System.Collections.Generic.IDictionary und kopieren Sie alle Werte von System.Collections.IDictionary.
Es ist immer effizient generic Wörterbuch zu verwenden (die auf System.Collections.Generic ist) über IDictionary (die auf System.Collections ist).