generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDatabaseMapper.cs
More file actions
36 lines (32 loc) · 2.18 KB
/
DatabaseMapper.cs
File metadata and controls
36 lines (32 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx
using CoreEx.Entities;
using CoreEx.Mapping;
using System;
namespace CoreEx.Database.Mapping
{
/// <summary>
/// Enables <see cref="Create{TSource}"/> or <see cref="CreateAuto{TSource}(string[])"/> of a <see cref="DatabaseMapper{TSource}"/>.
/// </summary>
public static class DatabaseMapper
{
/// <summary>
/// Creates a <see cref="DatabaseMapper{TSource}"/> where properties are added manually (leverages reflection).
/// </summary>
/// <returns>A <see cref="DatabaseMapper{TSource}"/>.</returns>
/// <remarks>Where performance is critical consider using <see cref="CreateExtended{TSource}"/>.</remarks>
public static DatabaseMapper<TSource> Create<TSource>() where TSource : class, new() => new(false);
/// <summary>
/// Creates a <see cref="DatabaseMapper{TSource}"/> where properties are added automatically using reflection (assumes the property, column and parameter names share the same name).
/// </summary>
/// <param name="ignoreSrceProperties">An array of source property names to ignore.</param>
/// <returns>A <see cref="DatabaseMapper{TSource}"/>.</returns>
/// <remarks>Where performance is critical consider using <see cref="CreateExtended{TSource}"/>.</remarks>
public static DatabaseMapper<TSource> CreateAuto<TSource>(params string[] ignoreSrceProperties) where TSource : class, new() => new(true, ignoreSrceProperties);
/// <summary>
/// Creates a <see cref="DatabaseMapperEx{TSource}"/> where the underlying implementation is added explicitly (extended, offers potential performance benefits).
/// </summary>
/// <returns>A <see cref="DatabaseMapperEx{TSource}"/>.</returns>
public static DatabaseMapperEx<TSource> CreateExtended<TSource>(Action<DatabaseRecord, TSource, OperationTypes>? mapFromDb = null, Action<CompositeKey, DatabaseParameterCollection>? mapKeyToDb = null, Action<TSource?, DatabaseParameterCollection, OperationTypes>? mapToDb = null) where TSource : class, new()
=> new(mapFromDb, mapKeyToDb, mapToDb);
}
}