Closed mk3008 closed 3 weeks ago
Model
public record StoreData : IDataRow
{
public int StoreDataId { get; set; }
public string StoreName { get; set; } = string.Empty;
// interface property
IDataSet IDataRow.DataSet { get; set; } = null!;
}
Test
[Fact]
public void SnakeCase_SelectColumn()
{
var sd = Sql.DefineDataSet<StoreData>();
var query = Sql.From(() => sd)
.Select(() => new
{
sd.StoreDataId,
sd.StoreName,
});
var actual = query.ToText();
Output.WriteLine(actual);
var expect = @"SELECT
sd.store_data_id,
sd.store_name
FROM
store_data AS sd";
Assert.Equal(expect, actual, true, true, true);
}
Result
SELECT
sd.StoreDataId,
sd.StoreName
FROM
store_data AS sd
Only the table names are in snake case. Column names are not converted to snake case.
This symptom itself can be solved, but the handling of alias names becomes very complicated.
For example,
new {
a.SaleDataId
}
can be interpreted as
a.sales_data_id
, but if an alias like
new {
SalesDataId2 = a.SaleDataId
}
is used, it is unclear whether it should be interpreted as
a.sales_data_id as sales_data_id2
or
a.sales_data_id as SalesDataId2
It is possible to uniformly use snake case, but this does not support cases where you do not want to do so.
So, unfortunately, I will stop "processing property names to use as column names" altogether.
When parsing an Expression, the property names are used as column names.