Skip to content

Cache Dialect when creating a session factory #1951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/NHibernate/Cfg/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,40 @@ public bool HasNonIdentifierPropertyNamedId(string className)
NHibernate.Dialect.Dialect.GetDialect(configuration.Properties);
}

[Serializable]
private class StaticDialectMappingWrapper : IMapping
{
private readonly IMapping _mapping;

public StaticDialectMappingWrapper(IMapping mapping)
{
_mapping = mapping;
Dialect = mapping.Dialect;
}

public IType GetIdentifierType(string className)
{
return _mapping.GetIdentifierType(className);
}

public string GetIdentifierPropertyName(string className)
{
return _mapping.GetIdentifierPropertyName(className);
}

public IType GetReferencedPropertyType(string className, string propertyName)
{
return _mapping.GetReferencedPropertyType(className, propertyName);
}

public bool HasNonIdentifierPropertyNamedId(string className)
{
return _mapping.HasNonIdentifierPropertyNamedId(className);
}

public Dialect.Dialect Dialect { get; }
}

private IMapping mapping;

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

return new SessionFactoryImpl(this, mapping, settings, GetInitializedEventListeners());
return new SessionFactoryImpl(this, new StaticDialectMappingWrapper(mapping), settings, GetInitializedEventListeners());
}

/// <summary>
Expand Down