Skip to content

Dynamic query #58

@SoftStoneDevelop

Description

@SoftStoneDevelop

Old way, only a pre-known query

[Query(
            @"
SELECT 
    p.id,
    p.firstname,
~StartInner::Identification:id~
    i.id,
    i.typename,
~EndInner::Identification~
    p.middlename,
    p.lastname
FROM person p
LEFT JOIN identification i ON i.id = p.identification_id
WHERE p.id > $1
",
        "GetAllPerson",
        typeof(Person),
        MethodType.Sync | MethodType.Async
        ),
        Parametr(parametrType: typeof(int), position: 1)
        ]
public class Person
//...

New way:

If parameters known:

[Query(
        "GetAllPerson",
        typeof(Person),
        MethodType.Sync | MethodType.Async,
        DynamicQuery: true),
        Parametr(parametrType: typeof(int), position: 1)
        ]
public class Person
//...

If parameters unknown:

[Query(
        "GetAllPerson",
        typeof(Person),
        MethodType.Sync | MethodType.Async,
        DynamicQuery: true),
        DynamicParametrs(PositionParametrs: true)
        ]
public class Person
//...

DynamicParameters means that the parameters are not known in advance. If PositionParametrs is true, the parameters are passed as Dictionary<int, NpgsqlParameter> where key is Position; otherwise, the parameters are passed as NpgsqlParameter[].

Metadata

Metadata

Labels

CommonGeneratorApplies to all supported providers

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions