using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication
public string Name { get; set; }
public int Population { get; set; }
public int id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public class POCO : BaseClass
public City City1 { get; set; }
public City City2 { get; set; }
public City City3 { get; set; }
public class Normalized<T> : BaseClass
public List<T> City { get; set; }
public static explicit operator Normalized<T>(POCO self)
var normal = new Normalized<T>();
foreach (var prop in typeof(BaseClass).GetProperties())
prop.SetValue(normal, prop.GetValue(self));
var complexProp = typeof(Normalized<T>).GetProperties().Where(x => x.PropertyType.GetInterfaces().Any(y => y.Name == "ICollection")).First();
complexProp.SetValue(normal, new List<T>((typeof(POCO).GetProperties().Where(x => x.Name.Contains(complexProp.Name)).Select(x => (T)x.GetValue(self)).ToList())));
public static void Main(string[] args)
City1 = new City { Name = "Moscow", Population = 10 },
City2 = new City { Name = "London", Population = 20 },
var normal = (Normalized<City>)fromDB;
Console.WriteLine(normal.City.Select(x => x == null ? "EMPTY" : x.Name).Aggregate((a, b) => { return a + ", " + b; }));