public List <Fabrica> createTable() { var farmManager = new FarmManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString); var factory = Fabrica.Text.Length > 0 ? Fabrica.Text.Trim() : null; var farm = Ferma.Text.Length > 0 ? Ferma.Text.Trim() : null; var cod = Code.Text.Length > 0 ? Code.Text.Trim() : null; var farms = farmManager.GetAllFarms(farm, cod); var factoryManager = new FactoryManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString); var factories = factoryManager.GetFactories(factory); var countiesManager = new CountyManager(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString); var counties = countiesManager.GetAllCounties(); var values = farms.Select(x => new Fabrica { id = x.Id.ToString(), cod = x.Cod, nume = x.Nume, numar = x.Numar, email = x.Email, telefon = x.Telefon, oras = x.Oras, strada = x.Strada, fabricaid = x.FabricaId.ToString(), judet = x.Judet }).ToList(); var farctorieslist = values.ToList(); foreach (var fabrica in farctorieslist) { var factoryEntity = factories.FirstOrDefault(x => x.Id.ToString(CultureInfo.InvariantCulture) == fabrica.fabricaid); if (factoryEntity == null) { values.Remove(fabrica); } else { fabrica.fabricaid = factoryEntity.Nume; } var countyEntity = counties.FirstOrDefault(x => x.Id.ToString(CultureInfo.InvariantCulture) == fabrica.judet); if (countyEntity != null) { fabrica.judet = countyEntity.DenLoc; } } lcount.Text = values.Count + " ferme"; return(values); }