我想在继续执行其他任何操作之前等待此查询。我已经看到了这个主题的几个问题,但是没有一个在查询中使用自定义函数,这使得它有点棘手。以下查询甚至可以使用await。我正在使用使用Microsoft异步包.NET4.0的await,异步(https://www.nuget.org/packages/Microsoft.Bcl.Async/)是否可以使用await和使用自定义函数的查询
var Employees =
(from d in context.Employees
join a in context.Address on d.ID equals a.EmployeeID
select new
{
Employee = d,
Address = a,
})
.AsEnumerable() memory
.Select(x => new Employee
{
Id = x.Employee.Id,
PreferredName = GetPreferredName(x.Employee.FirstName, x.Employee.MiddleName, x.Employee.LastName, x.Employee.Alias),
StreetAddress = x.Address.StreetAddress
})
.ToList();
private string GetPreferredName(string firstName, string middleName, string lastName, string dnsName)
{
if (!string.IsNullOrEmpty(firstName))
return firstName;
else if (!string.IsNullOrEmpty(middleName))
return middleName;
else if (!string.IsNullOrEmpty(lastName))
return lastName;
else if (!string.IsNullOrEmpty(dnsName))
return dnsName;
return "";
}
'ToListAsync'不接受'IEnumerable'。 – Servy
@Servy是的,没有注意到查询内部的'AsEnumerable'。固定。 –
感谢收到编译错误报道Servy答案 –