public FamousPersonInfo FindById(object id) { var person = famousPersonRepository.FindById(id); var typeIds = personTypeRelationRepository.FindByWhereAndSelect(p => p.FamousPersonId == (int)id, p => p.FamousPersonTypeId); return(FamousPersonConverter.ConvertToDto(person, (IEnumerable <int>)typeIds)); }
public IEnumerable <FamousPersonInfo> Search(PersonSearchModel searchModel) { //初始化查询sql语句 var sqlBuilder = new StringBuilder("select famousperson.* from famousperson join persontyperelation on famousperson.famousPersonId=persontyperelation.famouspersonId where "); //初始化查询参数 var searchParams = new List <object>(); //处理参数 DealStringQueryParam("PersonName", searchModel.PersonName, sqlBuilder, searchParams); DealStringQueryParam("Province", searchModel.Province, sqlBuilder, searchParams); DealStringQueryParam("Nation", searchModel.Nation, sqlBuilder, searchParams); DealStringQueryParam("BornPlace", searchModel.BornPlace, sqlBuilder, searchParams); DealStringQueryParam("DeadPlace", searchModel.DeadPlace, sqlBuilder, searchParams); if (searchModel.FamousPersonTypeId != null) { sqlBuilder.Append("persontyperelation.FamousPersonTypeId ={0} and "); searchParams.Add(searchModel.FamousPersonTypeId); } if (searchModel.MinBornDate != null) { sqlBuilder.Append("BornDate >={0} and "); searchParams.Add(searchModel.MinBornDate); } if (searchModel.MaxBornDate != null) { sqlBuilder.Append("BornDate <={0} and "); searchParams.Add(searchModel.MaxBornDate); } if (searchModel.MinDeadDate != null) { sqlBuilder.Append("DeadDate >={0} and "); searchParams.Add(searchModel.MinDeadDate); } if (searchModel.MaxDeadDate != null) { sqlBuilder.Append("DeadDate <={0} and "); searchParams.Add(searchModel.MaxDeadDate); } var personInfos = new List <FamousPersonInfo>(); //无任何查询参数 返回无元素的数组 if (searchParams.Count == 0) { return(personInfos); } //移除最后多余的"and " sqlBuilder.Remove(sqlBuilder.Length - 5, 4); //sql查询 var persons = famousPersonRepository.FindBySQL(sqlBuilder.ToString(), searchParams.ToArray()); foreach (var person in persons) { var typeIds = personTypeRelationRepository.FindByWhereAndSelect(p => p.FamousPersonId == person.FamousPersonId, p => p.FamousPersonTypeId).ToList(); personInfos.Add(FamousPersonConverter.ConvertToDto(person, (IEnumerable <int>)typeIds)); } return(personInfos); }
public IEnumerable <FamousPersonInfo> FindAll() { var persons = famousPersonRepository.FindAll(); var personInfos = new List <FamousPersonInfo>(); foreach (var person in persons) { var typeIds = personTypeRelationRepository.FindByWhereAndSelect(p => p.FamousPersonId == person.FamousPersonId, p => p.FamousPersonTypeId).ToList(); personInfos.Add(FamousPersonConverter.ConvertToDto(person, (IEnumerable <int>)typeIds)); } return(personInfos); }