• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 18406925343

10 Oct 2025 12:46PM UTC coverage: 88.061%. First build
18406925343

Pull #296

github

web-flow
Merge 39d6c8fd2 into fd45dbbc9
Pull Request #296: Add ClassMap-based type-safe appender API to DuckDB.NET

1154 of 1361 branches covered (84.79%)

Branch coverage included in aggregate %.

106 of 155 new or added lines in 4 files covered. (68.39%)

2239 of 2492 relevant lines covered (89.85%)

587198.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/DuckDB.NET.Data/Mapping/DuckDBClassMap.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq.Expressions;
4

5
namespace DuckDB.NET.Data.Mapping;
6

7
/// <summary>
8
/// Base class for defining mappings between .NET classes and DuckDB table columns.
9
/// </summary>
10
/// <typeparam name="T">The type to map</typeparam>
11
public abstract class DuckDBClassMap<T>
12
{
13
    private readonly List<PropertyMapping<T>> propertyMappings = new();
9✔
14

15
    /// <summary>
16
    /// Gets the property mappings defined for this class map.
17
    /// </summary>
18
    internal IReadOnlyList<PropertyMapping<T>> PropertyMappings => propertyMappings;
9✔
19

20
    /// <summary>
21
    /// Maps a property to the next column in sequence.
22
    /// </summary>
23
    /// <typeparam name="TProperty">The property type</typeparam>
24
    /// <param name="propertyExpression">Expression to select the property</param>
25
    /// <returns>The current map instance for fluent configuration</returns>
26
    protected void Map<TProperty>(Expression<Func<T, TProperty>> propertyExpression)
27
    {
28
        if (propertyExpression.Body is not MemberExpression memberExpression)
30!
29
        {
NEW
30
            throw new ArgumentException("Expression must be a member expression", nameof(propertyExpression));
×
31
        }
32

33
        var propertyName = memberExpression.Member.Name;
30✔
34
        var propertyType = typeof(TProperty);
30✔
35
        var getter = propertyExpression.Compile();
30✔
36

37
        var mapping = new PropertyMapping<T>
30✔
38
        {
30✔
39
            PropertyName = propertyName,
30✔
40
            PropertyType = propertyType,
30✔
41
            Getter = obj => getter(obj),
36✔
42
            MappingType = PropertyMappingType.Property
30✔
43
        };
30✔
44

45
        propertyMappings.Add(mapping);
30✔
46
    }
30✔
47

48
    /// <summary>
49
    /// Adds a default value for the next column.
50
    /// </summary>
51
    protected void DefaultValue()
52
    {
53
        var mapping = new PropertyMapping<T>
3✔
54
        {
3✔
55
            PropertyName = "<default>",
3✔
56
            PropertyType = typeof(object),
3✔
NEW
57
            Getter = _ => null,
×
58
            MappingType = PropertyMappingType.Default
3✔
59
        };
3✔
60

61
        propertyMappings.Add(mapping);
3✔
62
    }
3✔
63

64
    /// <summary>
65
    /// Adds a null value for the next column.
66
    /// </summary>
67
    protected void NullValue()
68
    {
69
        var mapping = new PropertyMapping<T>
3✔
70
        {
3✔
71
            PropertyName = "<null>",
3✔
72
            PropertyType = typeof(object),
3✔
NEW
73
            Getter = _ => null,
×
74
            MappingType = PropertyMappingType.Null
3✔
75
        };
3✔
76

77
        propertyMappings.Add(mapping);
3✔
78
    }
3✔
79
}
80

81
/// <summary>
82
/// Represents the type of mapping.
83
/// </summary>
84
internal enum PropertyMappingType
85
{
86
    Property,
87
    Default,
88
    Null
89
}
90

91
/// <summary>
92
/// Represents a mapping between a property and a column.
93
/// </summary>
94
internal class PropertyMapping<T>
95
{
96
    public string PropertyName { get; set; } = string.Empty;
75✔
97
    public Type PropertyType { get; set; } = typeof(object);
102✔
98
    public Func<T, object?> Getter { get; set; } = _ => null;
108✔
99
    public PropertyMappingType MappingType { get; set; }
117✔
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc