diff --git a/Documentation/Documentation.md b/Documentation/Documentation.md index 3c0af68..001b66c 100644 --- a/Documentation/Documentation.md +++ b/Documentation/Documentation.md @@ -3,3 +3,4 @@ - [Parametr](https://github.com/SoftStoneDevelop/Gedaq.DbConnection/blob/main/Documentation/Parametr.md) - [BatchPart](https://github.com/SoftStoneDevelop/Gedaq.DbConnection/blob/main/Documentation/QueryBatch.md) - [Custom mapping](https://github.com/SoftStoneDevelop/Gedaq.DbConnection/blob/main/Documentation/CustomMapping.md) +- [Reinterpret syntax](https://github.com/SoftStoneDevelop/Gedaq.DbConnection/blob/main/Documentation/Reinterpret.md) diff --git a/Documentation/Reinterpret.md b/Documentation/Reinterpret.md new file mode 100644 index 0000000..81ec10d --- /dev/null +++ b/Documentation/Reinterpret.md @@ -0,0 +1,80 @@ +The `~Reinterpret::NewName~` syntax allows you to interpret the column name that follows it as `NewName`. + +Model classes in example: +```C# + +public class Person +{ + public int ReinterpId { get; set; } + + public string Name1 { get; set; } + + public string Name2 { get; set; } + + public string FinalName { get; set; } + + public Identification Identification { get; set; } +} + +public class Identification +{ + public int Id { get; set; } + public string TypeName { get; set; } + public Country Country { get; set; } +} + +public class Country +{ + public int Id { get; set; } + public string Name { get; set; } +} + +``` + +Usage: + +```C# + +[Query( + @" +SELECT +~Reinterpret::ReinterpId~ + p.id, +~Reinterpret::Name1~ + p.firstname, +~StartInner::Identification:id~ + i.id, +~StartInner::Country:id~ + c.id, + c.name, +~EndInner::Country~ + i.typename, +~EndInner::Identification~ +~Reinterpret::Name2~ + p.middlename, +~Reinterpret::FinalName~ + p.lastname +FROM person p +LEFT JOIN identification i ON i.id = p.identification_id +LEFT JOIN country c ON c.id = i.country_id +ORDER BY p.id ASC +", + "GetAllPerson", + typeof(Person), + Gedaq.Common.Enums.MethodType.Async | Gedaq.Common.Enums.MethodType.Sync + )] +public async Task SomeMethod(DbConnection connection) +{ + var persons = connection.GetAllPerson().ToList(); + var personsAsync = await connection.GetAllPersonAsync().ToListAsync(); + + var id = connection.ScalarGetAllPerson();//return int because id in Person class is int + var idAsync = await connection.ScalarGetAllPersonAsync();//return int because id in Person class is int + + var rowsAffected = connection.NonQueryGetAllPerson();//return int because id in Person class is int + var rowsAffectedAsync = await connection.NonQueryGetAllPersonAsync();//return int because id in Person class is int + + var personsCommand = CreateGetAllPersonCommand(prepare: false); + var personsFromCommand = personsCommand.ExecuteGetAllPersonCommand().ToList(); +} +```