Initial Data Source
Dictionary<KeyValuePair<string, string>, List<string>> PropertyMap = new()
{
{ new("PACKAGE_TYPE", "PackageType"), new() },
{ new("TURNAROUND_TIME", "TurnaroundTime"), new() },
{ new("TRACKING", "Tracking"), new() }
};
Projection Target
public class PackageMetadata
{
public int PackageId { get; set; }
public string Key { get; set; }
[NotMapped]
public string SourceId { get; set; }
}
Populate Values
foreach (KeyValuePair<KeyValuePair<string, string>, List<string>> map in PropertyMap)
// Get PackageIds for records that have a value associated with column 'map.Key.Key'
map.Value.AddRange(await GetPackageIds(map.Key.Key));
Projection Method
List<PackageMetadata> FromPropertyMap() => PropertyMap
.SelectMany(x =>
x.Value.Select(y => new PackageMetadata
{
PackageId = y,
Key = x.Key.Value,
SourceId = $"{y}:{x.Key.Key}"
})
)
.ToList();