Constructors:
public BinaryImportAttribute(
string query,
string methodName,
Type queryMapType,
NpgsqlDbType[] dbTypes = null,
MethodType methodType = MethodType.Sync,
SourceType sourceType = SourceType.Connection,
AccessModifier accessModifier = AccessModifier.AsContainingClass,
AsyncResult asyncResultType = AsyncResult.ValueTask,
Type asPartInterface = null
)Parametrs:
query: sql query
methodName: name of the generated method
queryMapType: Type of result mapping collection
dbTypes: postgresql database types
methodType: type of generated method(sync/async, flags enum)
sourceType: type of connection source
accessModifier: Access Modifier of Generated Methods.
asyncResultType: The type of the generated Task/ValueTask method.
Model classes in example:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public Identification Identification { get; set; }
}
public class Identification
{
public int Id { get; set; }
public string TypeName { get; set; }
}Usage from table:
[BinaryImport(@"
COPY person
(
id,
firstname,
~StartInner::Identification:id~
~Reinterpret::id~
identification_id,
~EndInner::Identification~
middlename,
lastname
)
FROM STDIN (FORMAT BINARY)
",
"BinaryImport",
typeof(Person),
new NpgsqlDbType[]
{
NpgsqlDbType.Integer,//id
NpgsqlDbType.Text,//firstname
NpgsqlDbType.Integer,//identification_id
NpgsqlDbType.Text,//middlename
NpgsqlDbType.Text//lastname
},
Gedaq.Common.Enums.MethodType.Sync | Gedaq.Common.Enums.MethodType.Async
)]
public async Task SomeMethod(NpgsqlConnection connection, List<Person> list)
{
connection.BinaryImport(list);
await connection.BinaryImportAsync(list);
}