fluent-nhibernate icon indicating copy to clipboard operation
fluent-nhibernate copied to clipboard

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

Open bounav opened this issue 8 years ago • 0 comments

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?

bounav avatar Jun 13 '17 13:06 bounav