【发布时间】:2016-07-17 18:41:31
【问题描述】:
我有以下查询,但它抛出错误:
无法将 system.collections.generics.lists 隐式转换为 system.collections.generics.ienumerable
查询:
public IEnumerable<ApplicationUser> GetUsersByRole(string roleName)
{
var role = _context.Roles.FirstOrDefault(r => r.Name == roleName);
return _context.Users
.Where(u => u.Roles.Any(r => r.RoleId == role.Id))
.Select(u => new ApplicationUser { Id = u.Id, FullName = u.FullName })
.ToList();
}
在我的应用程序用户类中,Fullname 属性定义如下:
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get { return string.Format("{0} {1}", FirstName, LastName); }
}
}
我也有错误
属性 Indexer ApplicationUser.Fullname 不能分配给 -- 它是只读的
有没有办法在不添加 setter 的情况下保持 fullname 属性只读?
【问题讨论】:
-
.Select(u => new ApplicationUser { ... }).ToList();
标签: c# .net asp.net-mvc entity-framework linq-to-entities