【发布时间】:2017-01-03 13:23:06
【问题描述】:
嵌套 SELECT 时发生异常。如果您注释掉属性照片、生日和住所,那么一切正常。如何重写查询以使其正常工作?
var predicate = PredicateBuilder.True<Persons>();
var query = this._entity.Persons.AsExpandable();
#region
if (!String.IsNullOrEmpty(currentPerson.PersonName))
{
predicate = predicate.And(i => i.PersonName.Contains(currentPerson.PersonName.Trim()));
}
if (!String.IsNullOrEmpty(currentPerson.PersonLastName))
{
predicate = predicate.And(i => i.PersonLastName.Contains(currentPerson.PersonLastName.Trim()));
}
if (!String.IsNullOrEmpty(currentPerson.PersonPatronymic))
{
predicate = predicate.And(i => i.PersonPatronymic.Contains(currentPerson.PersonPatronymic.Trim()));
}
...........
var result = query.Where(predicate).AsEnumerable().Select(o => new POCO.PersonResult
{
Id = (int)o.Id,
Photo = o.persons_photos.Select(s => s.PersonFrontView).FirstOrDefault(),
FullName = String.Format("{0} {1} {2}", o.PersonLastName, o.PersonName, o.PersonPatronymic),
Birthday = o.persons_passport_data.Select(s => s.PersonBirthday).FirstOrDefault().ToString()
Residence = o.persons_registration
.Select(s =>
String.Join(", ", ListModel.GetCountry(s.PersonCountryId),
ListModel.GetRegion(s.PersonRegionId),
ListModel.GetCity(s.PersonCityId))).FirstOrDefault()
}).ToList();
【问题讨论】: