可以将映射提取到
func
将其委托为,并将其用作选择器。
Func<MyModel, AutoCompleteItem> selector = s => new AutoCompleteItem
{
Value = s.PersonnelNumber,
Text = s.FullName +
(string.IsNullOrEmpty((string.IsNullOrWhiteSpace(s.SectionCode) ? null : s.SectionCode) ?? (string.IsNullOrWhiteSpace(s.DivisionCode) ? null : s.DivisionCode)) ? string.Empty : " (") +
((string.IsNullOrWhiteSpace(s.SectionCode) ? null : s.SectionCode) ?? (string.IsNullOrWhiteSpace(s.DivisionCode) ? null : s.DivisionCode)) +
(string.IsNullOrEmpty((string.IsNullOrWhiteSpace(s.SectionCode) ? null : s.SectionCode) ?? (string.IsNullOrWhiteSpace(s.DivisionCode) ? null : s.DivisionCode)) ? string.Empty : ")") +
(string.IsNullOrEmpty(s.FirstPhoneNumber ?? s.SecondPhoneNumber) ? string.Empty : " (") +
(string.IsNullOrEmpty(s.FirstPhoneNumber ?? s.SecondPhoneNumber) ? string.Empty : ("x" + (s.FirstPhoneNumber ?? s.SecondPhoneNumber))) +
(string.IsNullOrEmpty(s.FirstPhoneNumber ?? s.SecondPhoneNumber) ? string.Empty : ")"),
Email = s.Email
};
你可以这样使用它:
_staffQueryService.ClearAllFilters().OnlyActiveStaff().ExcludeContractors()
.Get().Select(selector).AsQueryable();