Open denisenko93 opened 2 years ago
Is it possible to get some movement on this PR? Would be an immensely helpful feature for my use case
@denisenko93 I used your branch of the code. Thank you.
@denisenko93 This line of code has a bug: "sqlStringBuilder.Remove(sqlStringBuilder.Length - 3, 2);". The code is intended to remove the last comma, which works correctly on the Windows platform. However, on the Linux platform, it removes extra characters, resulting in issues with the SQL statement.
@denisenko93
Provide a feature suggestion to add not only the Attribute [Column(string)] but also a DbMetaDataNameCaseAttribute(enum DbMetaDataNameCase) class. When a class or class property has this attribute, it should convert the field to SnakeCase.
/// <summary>
/// Database metadata naming rules
/// </summary>
public enum DbMetaDataNameCase
{
/// <summary>
/// Snake case naming (snake_case)
/// For example: example_name
/// </summary>
SnakeCase,
}
[AttributeUsage(AttributeTargets.Class| AttributeTargets.Property)]
public class DbMetaDataNameCaseAttribute : Attribute
{
public DbMetaDataNameCaseAttribute(DbMetaDataNameCase dbMetaDataNameCase)
{
DbMetaDataNameCase = dbMetaDataNameCase;
}
public DbMetaDataNameCase DbMetaDataNameCase { get; set; }
}
private static string ConvertCamelCaseToSnakeCase(PropertyInfo property)
{
string name = property.Name;
string resultName = Regex.Replace(name, "([a-z])([A-Z])", "$1_$2").ToLower();
return resultName;
}
Added Attribute [Column(string)] for when the column in the DB is named differently from the Property in the model. Fixed #129
Breaking changes: