【发布时间】:2021-04-13 14:50:59
【问题描述】:
我有以下方法可以返回 LINQ 查询的输出。该方法工作得很好,但我有动态作为返回类型,因为以下 2 不起作用:List & IEnumerable。 LINQ 查询输出的正确返回类型应该是什么?我的方法:
public dynamic GetUserFollowers(Guid user_gd)
{
var listOfFollowers = from users in _context.Users
from userFollowing in _context.UserFollowings.Where(
uf => uf.User2 != users.Gd && uf.User2 == user_gd && uf.User1 == users.Gd
)
select new { users.Gd, users.Firstname, users.Lastname, users.Username, users.Email };
return listOfFollowers;
}
用户模型:
public class User
{
[Key]
public Guid Gd { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public byte[] PasswordHash { get; set; }
public byte[] PasswordSalt { get; set; }
}
使用列表时出错:
不能隐式转换类型'System.Linq.IQueryable>' 到 'System.Collections.Generic.List
'。 存在显式转换(您是否缺少演员表?)
使用 IEnumerable
不能隐式转换类型'System.Linq.IQueryable>' 到 'System.Collections.Generic.IEnumerable
'。 存在显式转换(您是否缺少演员表?)
我们将不胜感激!
【问题讨论】:
标签: c# linq asp.net-web-api