我想从3个表中使用LINQ返回一个IEnumerable<PortalUser>
但没有太多运气的数据。当我想返回的结果,这是IQueryable<PortalUser>
型的,我不知道我应该为了达到我的目标是做:LINQ IQueryable到IEnumerable
public Task<IEnumerable<PortalUser>> GetUsers(string accountCode)
{
var res = from u in _db.Users
join ur in _db.UserRoles on u.ContactGuid equals ur.ContactGuid
join r in _db.Roles on ur.RoleId equals r.Id
where ur.AccountCode == accountCode
select(new PortalUser(u.Id, u.FriendlyName, u.UserName, r.RoleName));
return res;
}
在我的选择,我尝试使用PortalUser
构造函数使PortalUsers,并认为这会给我我想要的,但显然不是。
public class PortalUser
{
public PortalUser(int id,string friendlyName,string username,string rolename)
{
Id = id.ToString();
Firstname = friendlyName.Split(' ')[0];
Lastname = friendlyName.Split(' ')[1];
Username = username;
Role = rolename;
}
public string Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Username { get; set; }
public string Role { get; set; }
}
我得到这个错误:
Cannot implicitly convert type
'System.Linq.IQueryable<BSAR.Services.Models.Outbound.Full.PortalUser>'
to'System.Threading.Tasks.TaskSystem.Collections.Generic.IEnumerable<BSAR.Services.Models.Outbound.Full.PortalUser'>
. An explicit conversion exists (are you missing a cast?)
难道你不明白什么错误消息?它期待着一个'任务',但你没有提供一个'任务'。你不能那样做。 – Servy
你能改变返回类型吗?如果没有,为什么不标记方法'async'和'return awa.res.ToListAsync()'?你最近想做什么? – CodeCaster