Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyacheslav committed Feb 27, 2023
2 parents 3cdeb21 + b31a6d6 commit f68e421
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
80 changes: 80 additions & 0 deletions Documentation/Reinterpret.md
Original file line number Diff line number Diff line change
@@ -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();
}
```

0 comments on commit f68e421

Please sign in to comment.