Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

QuoteTableAndColumns setting not honoured when mapping IList<KeyValuePair> to a table #565

Answered by hazzik
bounav asked this question in Q&A
Discussion options

I've recently discovered the SchemaMetadataUpdater.QuoteTableAndColumns setting when you configure fluent nhibernate.

This options tells nhibernate to escape all table and column names. For example a column named Key will be surrounded by [ and ] if you are using T-SQL or ` (backtick) if your database is mysql.

Example on how you could turn on the Quote Table and Columns options.

IPersistenceConfigurer configuration = MsSqlConfiguration.MsSql2012
                                                         .ConnectionString(connectionString)
                                                         .AdoNetBatchSize(1000);

var fluentConfig = Fluently.Configure()
                           .Database(configuration)
                           .ExposeConfiguration(SchemaMetadataUpdater.QuoteTableAndColumns)
                           .Mappings(m => m.FluentMappings.Add(fluentMappingTypes));

This setting seems to work fine until you try to map a IList<KeyValuePair> using the fluent table mapping as follow:

// Domain object
public class Foo
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IList<KeyValuePair> Parameters { get; set; }
}

// Mapping class
public class FooMap : ClassMap<Foo>
{
	public FooMap()
	{
		Id(x => x.Id).GeneratedBy.Assigned();
		Map(x => x.Name);
		HasMany(x => x.Parameters)
			.Table("FooParameter")
			.KeyColumn("Foo_id")
			.Component(c =>
			{
				// Without the Column name override trying to save an instance of Foo will fail
				c.Map(x => x.Key).ColumnName("[Key]"));
				c.Map(x => x.Value);
			})
			.Cascade.AllDeleteOrphan();
	}
}

Am I wrong to assume that the c.Map(x => x.Key) and c.Map(x.Value) should automatically quote the column names?

You must be logged in to vote

I think this was fixed in around NH 5

Replies: 1 comment · 1 reply

Comment options

I think this was fixed in around NH 5

You must be logged in to vote
1 reply
@bounav
Comment options

It's been a while since this was originally asked ;). I checked in our project and we no longer have any trace of using .ColumnName() so I'll assume it has been fixed as you suggested.

Answer selected by bounav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #377 on October 12, 2022 23:26.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.