Skip to content

Commit

Permalink
Change default naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Nov 30, 2024
1 parent 7a97e80 commit 000b125
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
14 changes: 7 additions & 7 deletions SqlMarshal.Tests/CrudGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ partial class C
var connection = this.connection;
using var command = connection.CreateCommand();
var sqlQuery = @""SELECT Id, Name FROM TestEntity"";
var sqlQuery = @""SELECT id, name FROM test_entity"";
command.CommandText = sqlQuery;
using var reader = command.ExecuteReader();
var result = new List<TestEntity>();
Expand Down Expand Up @@ -139,7 +139,7 @@ partial class C
idParameter,
};
var sqlQuery = @""SELECT Id, Name FROM TestEntity WHERE Id = @id"";
var sqlQuery = @""SELECT id, name FROM test_entity WHERE id = @id"";
command.CommandText = sqlQuery;
command.Parameters.AddRange(parameters);
using var reader = command.ExecuteReader(System.Data.CommandBehavior.SingleResult | System.Data.CommandBehavior.SingleRow);
Expand Down Expand Up @@ -209,7 +209,7 @@ public partial int Count()
var connection = this.connection;
using var command = connection.CreateCommand();
var sqlQuery = @""SELECT COUNT(1) FROM TestEntity"";
var sqlQuery = @""SELECT COUNT(1) FROM test_entity"";
command.CommandText = sqlQuery;
var result = command.ExecuteScalar();
return (int)result!;
Expand Down Expand Up @@ -267,7 +267,7 @@ public partial void DeleteAll()
var connection = this.connection;
using var command = connection.CreateCommand();
var sqlQuery = @""DELETE FROM TestEntity"";
var sqlQuery = @""DELETE FROM test_entity"";
command.CommandText = sqlQuery;
command.ExecuteNonQuery();
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public partial void DeleteById(int id)
idParameter,
};
var sqlQuery = @""DELETE FROM TestEntity WHERE Id = @id"";
var sqlQuery = @""DELETE FROM test_entity WHERE id = @id"";
command.CommandText = sqlQuery;
command.Parameters.AddRange(parameters);
command.ExecuteNonQuery();
Expand Down Expand Up @@ -412,7 +412,7 @@ public partial void Update(int id, string name, string description)
descriptionParameter,
};
var sqlQuery = @""UPDATE TestEntity SET Name = @name, Description = @description WHERE Id = @id"";
var sqlQuery = @""UPDATE test_entity SET name = @name, description = @description WHERE id = @id"";
command.CommandText = sqlQuery;
command.Parameters.AddRange(parameters);
command.ExecuteNonQuery();
Expand Down Expand Up @@ -491,7 +491,7 @@ public partial void Insert(int id, string name, string description)
descriptionParameter,
};
var sqlQuery = @""INSERT INTO TestEntity(Id, Name, Description) VALUES (@id, @name, @description)"";
var sqlQuery = @""INSERT INTO test_entity(id, name, description) VALUES (@id, @name, @description)"";
command.CommandText = sqlQuery;
command.Parameters.AddRange(parameters);
command.ExecuteNonQuery();
Expand Down
3 changes: 3 additions & 0 deletions SqlMarshal.Tests/NameMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class NameMapperTests
{
[DataTestMethod]
[DataRow("personId", "person_id")]
[DataRow("name", "name")]
[DataRow("Name", "name")]
[DataRow("PersonId", "person_id")]
public void MyTestMethod(string parameterName, string expectedStoredProcedureParameter)
{
var storedProcedureParameter = NameMapper.MapName(parameterName);
Expand Down
24 changes: 12 additions & 12 deletions SqlMarshal/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,15 +785,15 @@ private void MapResults(
for (var i = 0; i < properties.Count; i++)
{
builder.Append(" ");
builder.Append(properties[i].Name);
builder.Append(NameMapper.MapName(properties[i].Name));
if (i != properties.Count - 1)
{
builder.Append(",");
}
}

builder.Append(" FROM ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
return builder.ToString();
}

Expand All @@ -805,15 +805,15 @@ private void MapResults(
for (var i = 0; i < properties.Count; i++)
{
builder.Append(" ");
builder.Append(properties[i].Name);
builder.Append(NameMapper.MapName(properties[i].Name));
if (i != properties.Count - 1)
{
builder.Append(",");
}
}

builder.Append(" FROM ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
AppendFilterById(builder);
return builder.ToString();
}
Expand All @@ -822,23 +822,23 @@ private void MapResults(
{
var builder = new StringBuilder();
builder.Append("SELECT COUNT(1) FROM ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
return builder.ToString();
}

if (canonicalOperationName == "DeleteAll")
{
var builder = new StringBuilder();
builder.Append("DELETE FROM ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
return builder.ToString();
}

if (canonicalOperationName == "DeleteById")
{
var builder = new StringBuilder();
builder.Append("DELETE FROM ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
AppendFilterById(builder);
return builder.ToString();
}
Expand All @@ -847,7 +847,7 @@ private void MapResults(
{
var builder = new StringBuilder();
builder.Append("UPDATE ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
builder.Append(" SET ");
bool first = true;
foreach (var parameter in methodGenerationContext.SqlParameters)
Expand All @@ -869,7 +869,7 @@ private void MapResults(
continue;
}

builder.Append(entityProperty.Name);
builder.Append(NameMapper.MapName(entityProperty.Name));
builder.Append(" = ");
builder.Append("@" + NameMapper.MapName(parameter.Name));
first = false;
Expand All @@ -883,7 +883,7 @@ private void MapResults(
{
var builder = new StringBuilder();
builder.Append("INSERT INTO ");
builder.Append(entityType.Name);
builder.Append(NameMapper.MapName(entityType.Name));
builder.Append("(");
bool first = true;
foreach (var parameter in methodGenerationContext.SqlParameters)
Expand All @@ -900,7 +900,7 @@ private void MapResults(
continue;
}

builder.Append(entityProperty.Name);
builder.Append(NameMapper.MapName(entityProperty.Name));
first = false;
}

Expand Down Expand Up @@ -942,7 +942,7 @@ void AppendFilterById(StringBuilder builder)
return;
}

builder.Append(idMember.Name);
builder.Append(NameMapper.MapName(idMember.Name));
builder.Append(" = ");
builder.Append("@" + NameMapper.MapName(idMember.Name));
}
Expand Down

0 comments on commit 000b125

Please sign in to comment.