Skip to content

Conversation

denisenko93
Copy link

@denisenko93 denisenko93 commented Mar 1, 2022

Added Attribute [Column(string)] for when the column in the DB is named differently from the Property in the model. Fixed #129

Breaking changes:

  • In ISqlAdapter changed method AppendColumnNameEqualsValue
  • Tables in database should contains columns for all properties

@JoeBerkley
Copy link

Is it possible to get some movement on this PR? Would be an immensely helpful feature for my use case

@feiazifeiazi
Copy link

@denisenko93 I used your branch of the code. Thank you.

@feiazifeiazi
Copy link

@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.

@feiazifeiazi
Copy link

feiazifeiazi commented Jun 24, 2024

@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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

need to add Annotation for Column Name

3 participants