【发布时间】:2014-07-11 11:09:27
【问题描述】:
我正在尝试使用 linq 查询将 x 中的所有项目设置为列表
我收到了错误
无法将类型“string”隐式转换为“system.collection.generic.List”
int 也一样
public List<AuthorityLevelList> GetUserAuthLevelListnew()
{
try
{
return db.ap_GetAuthorityLevelList()
.Select(c => new AuthorityLevelList{ UserAuthorityLevel2 = c.UserAuthorityLevel.ToList() , ID = c.ID })
.ToArray();
}
catch (Exception ex)
{
throw ex;
}
}
public partial class AuthorityLevelList
{
public List<int> ID { get; set; }
public List<string> UserAuthorityLevel2 { get; set; }
}
主要问题是我如何设置 linq 以返回一个列表而不仅仅是一个字符串,我想要列表 UserAuthorityLevel2 中表列 x 中的所有项目以及 int ID 的相同
请帮忙
【问题讨论】:
-
所以;我可以检查一下 - 你想返回一个包含所有项目的 single
AuthorityLevelList实例,是吗? -
ap_GetAuthorityLevelList()返回值的类型是什么? -
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction
("ap_GetUserAuthorityLevelListItems"); -
@Marc Gravell 是的,我希望“AuthorityLevelList”包含 authlevels 的所有项目。和 Id 有一个 ID 列表
-
顺便说一句;不要
try/catch,如果你唯一要做的就是throw或throw ex;——那完全没有意义