Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emilianomusso/db2ent
Database table records to List<> of new POCO with properties
https://github.com/emilianomusso/db2ent
database orm poco poco-generator records seed
Last synced: 4 days ago
JSON representation
Database table records to List<> of new POCO with properties
- Host: GitHub
- URL: https://github.com/emilianomusso/db2ent
- Owner: EmilianoMusso
- Created: 2020-11-15T12:32:04.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T14:45:59.000Z (about 4 years ago)
- Last Synced: 2023-09-18T11:28:39.621Z (over 1 year ago)
- Topics: database, orm, poco, poco-generator, records, seed
- Language: C#
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![.NET Core](https://github.com/EmilianoMusso/db2ent/workflows/.NET%20Core/badge.svg)
## db2ent
###### Database table records to List<> of new POCO with properties**db2ent** is a tool useful to read a table from a database, translating the read records to a C# List<>, composed by
objects with type derived from table name, and properties setting from the record itself.
It can be used to quickly generate seed instructions, to be used for example in ORMs like Entity Framework.###### Usage
```
db2ent --connectionstring="Data Source=INSTANCE;Initial Catalog=MYDB;User Id=MYUSER;Password=MYPASS" --tablename=MYTABLE [--numrecords=99999] [--where=CONDITIONAL_CLAUSE]
```_tablename_ parameter accept also a list of tables, with comma-separated names, in the form of:
```
--tablename=MYTABLE01,MYTABLE02,MYTABLE03 [...]
```Currently, db2ent outputs to console only. To save its results to file, you can pipe the execution towards a file path
###### Example
Lets consider a SQL table, named _Comuni_ with the following fields:```sql
[CodStato] [varchar](3) NOT NULL,
[CodProvincia] [varchar](2) NOT NULL,
[Comune] [varchar](25) NOT NULL,
[CodRegione] [varchar](6) NOT NULL,
[DesEstesa] [varchar](40) NOT NULL,
[Cap] [varchar](10) NOT NULL,
[PrefTelefonico] [varchar](4) NOT NULL,
[CodiceIrpef] [varchar](4) NOT NULL,
[CodiceIstat] [int] NOT NULL,
[FirmaUltVarData] [date] NOT NULL,
[FirmaUltVarOra] [int] NOT NULL,
[FirmaUltVarStazione] [varchar](2) NOT NULL,
[FirmaUltVarOperatore] [varchar](20) NOT NULL,
[CodLatitudine] [decimal](15, 4) NOT NULL,
[CodLongitudine] [decimal](15, 4) NOT NULL,
[DataInizioValidita] [date] NOT NULL,
[DataFineValidita] [date] NOT NULL
```We can execute db2ent to filter only those records which have field CodProvincia = 'AT', like this
```
db2ent --connectionstring="CONNECTION_STRING" --tablename=Comuni --where=CodProvincia='AT'
```And our output will be like the following:
```csharp
var comuniList = new List()
{
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "AGLIANO",
CodRegione = "13",
DesEstesa = "AGLIANO",
Cap = "14041",
PrefTelefonico = "",
CodiceIrpef = "A072",
CodiceIstat = 5001,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 44.7912,
CodLongitudine = 8.2515,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "ALBUGNANO",
CodRegione = "13",
DesEstesa = "ALBUGNANO",
Cap = "14022",
PrefTelefonico = "",
CodiceIrpef = "A173",
CodiceIstat = 5002,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 45.0785,
CodLongitudine = 7.9722,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "ANTIGNANO",
CodRegione = "13",
DesEstesa = "ANTIGNANO",
Cap = "14010",
PrefTelefonico = "",
CodiceIrpef = "A312",
CodiceIstat = 5003,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 44.8463,
CodLongitudine = 8.1360,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "ARAMENGO",
CodRegione = "13",
DesEstesa = "ARAMENGO",
Cap = "14020",
PrefTelefonico = "",
CodiceIrpef = "A352",
CodiceIstat = 5004,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 45.1018,
CodLongitudine = 8.0011,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "ASTI",
CodRegione = "13",
DesEstesa = "ASTI",
Cap = "14100",
PrefTelefonico = "",
CodiceIrpef = "A479",
CodiceIstat = 5005,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 44.8989,
CodLongitudine = 8.2079,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "AZZANO D'ASTI",
CodRegione = "13",
DesEstesa = "AZZANO D'ASTI",
Cap = "14030",
PrefTelefonico = "",
CodiceIrpef = "A527",
CodiceIstat = 5006,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 44.8744,
CodLongitudine = 8.2679,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
new Comuni()
{
CodStato = "IT",
CodProvincia = "AT",
Comune = "BALDICHIERI D'ASTI",
CodRegione = "13",
DesEstesa = "BALDICHIERI D'ASTI",
Cap = "14011",
PrefTelefonico = "",
CodiceIrpef = "A588",
CodiceIstat = 5007,
FirmaUltVarData = new DateTime(1800, 1, 1, 0, 0, 0),
FirmaUltVarOra = 0,
FirmaUltVarStazione = "",
FirmaUltVarOperatore = "",
CodLatitudine = 44.9069,
CodLongitudine = 8.0927,
DataInizioValidita = new DateTime(1800, 1, 1, 0, 0, 0),
DataFineValidita = new DateTime(1800, 1, 1, 0, 0, 0),
},
// Truncated data for demonstrative purposes
}
```db2ent produces also class representations.
Given the schema seen above as an example, the program will output the following code:```csharp
public partial class Comuni
{
public string CodStato {get; set;}
public string CodProvincia {get; set;}
public string Comune {get; set;}
public string CodRegione {get; set;}
public string DesEstesa {get; set;}
public string Cap {get; set;}
public string PrefTelefonico {get; set;}
public string CodiceIrpef {get; set;}
public Int32 CodiceIstat {get; set;}
public DateTime FirmaUltVarData {get; set;}
public Int32 FirmaUltVarOra {get; set;}
public string FirmaUltVarStazione {get; set;}
public string FirmaUltVarOperatore {get; set;}
public Decimal CodLatitudine {get; set;}
public Decimal CodLongitudine {get; set;}
public DateTime DataInizioValidita {get; set;}
public DateTime DataFineValidita {get; set;}
}
```