using System.Collections.Generic;
public static void Main()
List<Hospital> hospitals = new List<Hospital>
List<Hospital> fetched = new List<Hospital>
.Select(h => new Hospital { HospitalId = h.HospitalId, Phone = h.Phone })
.Except(fetched, new HospitalEqualityComparer())
var hospitalsResult = hospitals
.Where(h => result.Select(r => r.HospitalId).Contains(h.HospitalId))
string json = JsonConvert.SerializeObject(result, Formatting.Indented);
string json2 = JsonConvert.SerializeObject(hospitalsResult, Formatting.Indented);
Console.WriteLine(json2);
public class HospitalEqualityComparer: IEqualityComparer<Hospital>
public bool Equals(Hospital f1, Hospital f2) {
if (f1 == null && f2 == null)
else if (f1 == null || f2 == null)
else if (f1.HospitalId == f2.HospitalId && f1.Phone == f2.Phone)
public int GetHashCode(Hospital f1)
if (Object.ReferenceEquals(f1, null)) return 0;
int hashFetchPhone = f1.Phone == null ? 0 : f1.Phone.GetHashCode();
int hashFetchId = f1.HospitalId.GetHashCode();
return hashFetchPhone ^ hashFetchId;
public partial class Hospital
public int HospitalId { get; set; }
public string Phone { get; set; }