Skip to content

4.2. Working with array types

Vedran Bilopavlović edited this page Mar 26, 2021 · 4 revisions

Mapping the array types

Norm also supports mapping the array types for all mapping extensions, for databases that support the array types (PostgreSQL for example).

Examples:

using System.Linq;
//...

var id = connection.Read<int[]>("select array_agg(id) from table").Single();
// id is int[]
var results = connection.Read<int[]>("select array_agg(id) from table").Single();
// `result` is IEnumerable<int[]>
var (ids, values) = connection.Read<int[], string[]>("select array_agg(id), array_agg(value) from table");
// `ids` is IEnumerable<int[]> and `values` is IEnumerable<string[]>
public class Test
{
    public int[] Ids { get; set; }
    public string[] Foos { get; set; }
}

//...

var results = connection.Read<Test>("select array_agg(id) as ids, array_agg(foo) as foos from table");

See also