using System.Text.RegularExpressions;
using System.Collections.Generic;
public static void Main()
List<Customer> customers = new List<Customer>(){
new Customer() {ID = 1, IsActive = true,TC="",Name="John", Surname="Snow",Email="",Address="",Phone="",AccountID=1 },
new Customer() {ID = 2, IsActive = true,TC="",Name="Mark", Surname="Zuck",Email="",Address="",Phone="",AccountID=1 },
new Customer() {ID = 3, IsActive = true,TC="",Name="Raptor", Surname="One",Email="",Address="",Phone="",AccountID=1 }
List<Patient> patients = new List<Patient>(){
new Patient() {PatientID = 1, PatientName = "Oscar",CustomerID=1 },
new Patient() {PatientID = 2, PatientName = "Puffy",CustomerID=1 },
new Patient() {PatientID = 3, PatientName = "Mars",CustomerID=2 },
var result1 = (from p in customers
join f in patients on p.ID equals f.CustomerID
where p.AccountID == AccountID
group new { f, p } by f.CustomerID into g
select new CustomerPageModel
IsActive = g.First().p.IsActive,
Surname = g.First().p.Surname,
Email = g.First().p.Email,
Address = g.First().p.Address,
Phone = g.First().p.Phone,
AccountID = g.First().f.AccountID,
Pats = string.Join(",", g.Select(x => x.f.PatientName)),
var result2 = (from p in customers
where p.AccountID == AccountID && !result1.Any(f => f.ID == p.ID)
select new CustomerPageModel
var allCustomers = result1.Concat(result2).ToList();
foreach(var item in allCustomers)
Console.WriteLine(String.Format("ID : {0} and CustomerName : {1} and Pats {2} and PatCount {3}",item.ID,item.Name,item.Pats,item.PatCount));
public int ID { get; set; }
public bool IsActive { get; set; }
public string TC { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Note { get; set; }
public int AccountID { get; set; }
public int PatientID { get; set; }
public bool IsActive { get; set; }
public int TypePatientID { get; set; }
public string TypeRace { get; set; }
public string CIPCode { get; set; }
public string Color { get; set; }
public string PatientName { get; set; }
public int Status { get; set; }
public int GenderID { get; set; }
public DateTime BirthDate { get; set; }
public DateTime? DeathDate { get; set; }
public int CustomerID { get; set; }
public int AccountID { get; set; }
public class CustomerPageModel
public int ID { get; set; }
public bool IsActive { get; set; }
public string TC { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Note { get; set; }
public int AccountID { get; set; }
public string Pats { get; set; }
public int PatCount { get; set; }