void fillCombos(ComboBox c_dem, ComboBox c_sup, bool asEdit = false) { Supply[] supplies; Demand[] demands; Demand ld = c_dem.SelectedItem as Demand; Supply ls = c_sup.SelectedItem as Supply; if (ld == null) { supplies = ModelContext.init().Supplies.Include(s => s.Deal).Include(s => s.Realty).Include(s => s.Realty.Earth).Include(s => s.Realty.Flat).Include(s => s.Realty.House).ToArray(); } else { supplies = ModelContext.init().Supplies.Include(s => s.Deal).Include(s => s.Realty).Include(s => s.Realty.Earth).Include(s => s.Realty.Flat).Include(s => s.Realty.House).AsEnumerable() .Where(s => s.Compare(ld)).ToArray(); } if (ls == null) { demands = ModelContext.init().Demands.Include(i => i.Deal).Include(i => i.HouseDemand).Include(i => i.EarthDemand).Include(i => i.FlatDemand).ToArray(); } else { demands = ModelContext.init().Demands.Include(i => i.Deal).Include(i => i.HouseDemand).Include(i => i.EarthDemand).Include(i => i.FlatDemand).AsEnumerable().Where(d => ls.Compare(d)).ToArray(); } supplies = supplies.Where(s => s.Deal == null || asEdit && (ls != null && s.ID == ls.ID)).ToArray(); demands = demands.Where(s => s.Deal == null || asEdit && (ld != null && s.ID == ld.ID)).ToArray(); c_sup.Items.Clear(); c_dem.Items.Clear(); c_sup.Items.AddRange(supplies); c_dem.Items.AddRange(demands); if (demands.Contains(ld)) { c_dem.SelectedItem = ld; } if (supplies.Contains(ls)) { c_sup.SelectedItem = ls; } }