using System.Collections;
using System.Collections.Generic;
using System.Data.DataSetExtensions;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.Globalization;
public static void Main()
List<DogOwner> dogowners = new List<DogOwner>()
new DogOwner() {OwnerId = 1, Dogs = new List<Dog>() {new Dog(), new Dog()}},
new DogOwner() {OwnerId = 2, Dogs = new List<Dog>() {new Dog(), new Dog()}}
List<CatOwner> catowners = new List<CatOwner>()
new CatOwner() {OwnerId = 1, Cats = new List<Cat>() {new Cat(), new Cat()}},
new CatOwner() {OwnerId = 2, Cats = new List<Cat>() { new Cat()}}
var results = dogowners.Select(x=> new Owner() {OwnerId = x.OwnerId, DogsCount = x.Dogs.Count()})
.Concat(catowners.Select(x=> new Owner() {OwnerId = x.OwnerId, CatsCount = x.Cats.Count()}))
.Select(x=> new Owner() {OwnerId = x.Key, DogsCount = x.Sum(s=>s.DogsCount), CatsCount = x.Sum(s=>s.CatsCount)})
Dictionary<int, Owner> owners = new Dictionary<int, Owner>();
foreach(var dg in dogowners)
if(owners.ContainsKey(dg.OwnerId))
owners[dg.OwnerId].DogsCount += dg.Dogs.Count();
owners.Add(dg.OwnerId, new Owner()
DogsCount = dg.Dogs.Count()
foreach(var ct in catowners)
if(owners.ContainsKey(ct.OwnerId))
owners[ct.OwnerId].CatsCount += ct.Cats.Count();
owners.Add(ct.OwnerId, new Owner()
CatsCount = ct.Cats.Count()
public int OwnerId {get;set;}
public List<Dog> Dogs {get;set;}
public int OwnerId {get;set;}
public List<Cat> Cats {get;set;}
public int OwnerId {get;set;}
public int DogsCount {get;set;}
public int CatsCount {get;set;}