Skip to content

Commit cbc2527

Browse files
maca88fredericDelaporte
authored andcommitted
Cache Dialect when creating a session factory
1 parent df84e62 commit cbc2527

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/NHibernate/Cfg/Configuration.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,40 @@ public bool HasNonIdentifierPropertyNamedId(string className)
239239
NHibernate.Dialect.Dialect.GetDialect(configuration.Properties);
240240
}
241241

242+
[Serializable]
243+
private class StaticDialectMappingWrapper : IMapping
244+
{
245+
private readonly IMapping _mapping;
246+
247+
public StaticDialectMappingWrapper(IMapping mapping)
248+
{
249+
_mapping = mapping;
250+
Dialect = mapping.Dialect;
251+
}
252+
253+
public IType GetIdentifierType(string className)
254+
{
255+
return _mapping.GetIdentifierType(className);
256+
}
257+
258+
public string GetIdentifierPropertyName(string className)
259+
{
260+
return _mapping.GetIdentifierPropertyName(className);
261+
}
262+
263+
public IType GetReferencedPropertyType(string className, string propertyName)
264+
{
265+
return _mapping.GetReferencedPropertyType(className, propertyName);
266+
}
267+
268+
public bool HasNonIdentifierPropertyNamedId(string className)
269+
{
270+
return _mapping.HasNonIdentifierPropertyNamedId(className);
271+
}
272+
273+
public Dialect.Dialect Dialect { get; }
274+
}
275+
242276
private IMapping mapping;
243277

244278
protected Configuration(SettingsFactory settingsFactory)
@@ -1272,7 +1306,7 @@ public ISessionFactory BuildSessionFactory()
12721306
// Ok, don't need schemas anymore, so free them
12731307
Schemas = null;
12741308

1275-
return new SessionFactoryImpl(this, mapping, settings, GetInitializedEventListeners());
1309+
return new SessionFactoryImpl(this, new StaticDialectMappingWrapper(mapping), settings, GetInitializedEventListeners());
12761310
}
12771311

12781312
/// <summary>

0 commit comments

Comments
 (0)