Columns that contain dots are unexpectedly escaped
Whenever a table has a column that contains a dot, it's escaped in way I don't want it to be escaped. Note: I am using the SqlServerCompiler class and have not tested it for other drivers.
Example, your table is products and it contains the column product.id and you use the query builder to build an insert query like this.
_queryFactory.Query("products").AsInsert(new { "product.id" = 5 })
It will generate a SQL query like: INSERT INTO products ([product].[id]) VALUES (5) instead of the (in my case) desired INSERT INTO products ([product.id]) VALUES (5). The escaping happens in the Wrap method of the compiler.
It's a difficult issue, because in some cases you actually want the generated query and in some cases the desired query. I've added a workaround like this.
public class CustomSqlServerCompiler : SqlServerCompiler
{
public bool EscapeDots { get; set; } = false;
public override string Wrap(string value)
{
if (!EscapeDots) return base.Wrap(value);
value = value.Replace(".", "_______");
value = base.Wrap(value);
return value.Replace("_______", ".");
}
}
This way I can prevent the behaviour when I want it to by changing the property EscapeDots. However it's quite a dirty solution (if a table would have the ___'s in their table it would do unexpected things). Does anyone know a better approach? And are there plans to implement a 'fix' in the project itself?