public void Expression_Test() { var query = new QueryMunicipalityByNameAndDistrict { Name = "Name", District = "District" }; var data = new[] { new Municipality { Name = "A" }, new Municipality { Name = "Name", DistrictName = "District" }, new Municipality { Name = "B" }, }; var result = data.SingleOrDefault(query.Expression.Compile()); Assert.AreEqual("Name", result?.Name); Assert.AreEqual("District", result?.DistrictName); }
private IEnumerable <Municipality> FindMunicipalitiesByNameWithDiscrict(string municipalityName) { if (municipalityName == null) { return(new Municipality[0]); } IQuery <Municipality> query; if (municipalityName.Contains(",")) { var parts = municipalityName.Split(','); query = new QueryMunicipalityByNameAndDistrict { Name = parts[0], District = parts[1] }; } else { query = new QueryMunicipalityByName { Name = municipalityName }; } return(MunicipalityRepository.FindAll(query)); }