mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
added marr.datamapper source code for easy debugging.
This commit is contained in:
parent
58a05fcef8
commit
3cdff3bb71
96 changed files with 9198 additions and 363 deletions
37
Marr.Data/EntityMerger.cs
Normal file
37
Marr.Data/EntityMerger.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Marr.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// This utility class allows you to join two existing entity collections.
|
||||
/// </summary>
|
||||
public class EntityMerger
|
||||
{
|
||||
/// <summary>
|
||||
/// Joines to existing entity collections.
|
||||
/// </summary>
|
||||
/// <typeparam name="TParent">The parent entity type.</typeparam>
|
||||
/// <typeparam name="TChild">The child entity type.</typeparam>
|
||||
/// <param name="parentList">The parent entities.</param>
|
||||
/// <param name="childList">The child entities</param>
|
||||
/// <param name="relationship">A predicate that defines the relationship between the parent and child entities. Returns true if they are related.</param>
|
||||
/// <param name="mergeAction">An action that adds a related child to the parent.</param>
|
||||
public static void Merge<TParent, TChild>(IEnumerable<TParent> parentList, IEnumerable<TChild> childList, Func<TParent, TChild, bool> relationship, Action<TParent, TChild> mergeAction)
|
||||
{
|
||||
foreach (TParent parent in parentList)
|
||||
{
|
||||
foreach (TChild child in childList)
|
||||
{
|
||||
if (relationship(parent, child))
|
||||
{
|
||||
mergeAction(parent, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue